我该如何运行该程序 [英] How do I run the program

查看:114
本文介绍了我该如何运行该程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我运行它,都会说返回外部功能。我该怎么办?



我的尝试:



Every time I run it, it says return outside function. What do I do?

What I have tried:

chars = "ACGT"

def neighbors(pattern, d):
    assert(d <= len(pattern))

if d == 0:
    return [pattern]

r2 = neighbors(pattern[1:], d-1)
r = [c + r3 for r3 in r2 for c in chars if c != pattern[0]]

if (d < len(pattern)):
    r2 = neighbors(pattern[1:], d)
    r += [pattern[0] + r3 for r3 in r2]

return r

推荐答案

如果你得到一条错误消息你不明白,谷歌它:返回外部功能 - Google搜索 [ ^ ]和f如果您只是阅读错误消息,那么很明显!
If you get an error message you don;t understand, Google it: return outside function - Google Search[^] and follow a few links.
It's pretty obvious if you just read the error message!


在python中,缩进非常重要。邻居定义中的所有内容都应至少缩进一次。
In python the indentation is important. Everything that belongs in the definition of neighbors should be indented at least once.


引用:

每次我跑它,它说返回外部功能。我该怎么办?

Every time I run it, it says return outside function. What do I do?



使用Python,缩进很重要,它是程序的结构,它不仅仅是演示文稿。需要格外小心。


With Python, indentation matters, it is the structure of your program, it is not just presentation. Need to be extra careful with it.

chars = "ACGT"

def neighbors(pattern, d):
    assert(d <= len(pattern))

    if d == 0:
        return [pattern]
    
    r2 = neighbors(pattern[1:], d-1)
    r = [c + r3 for r3 in r2 for c in chars if c != pattern[0]]
    
    if (d < len(pattern)):
        r2 = neighbors(pattern[1:], d)
        r += [pattern[0] + r3 for r3 in r2]
    
    return r


这篇关于我该如何运行该程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆