我是python的初学者,我正在尝试制作一个程序,询问你吉他的哪个音符是什么。在
我已经修改了一些代码,但是现在错误显示-
Traceback (most recent call last):
File "C:\Users\Jesse\Documents\Documents\Games I have created\Python games\Guitar Memorization.py", line 107, in <module>
print (guessing(string, question_type, correct, notes, guess, note, other_string, guessed))
File "C:\Users\Jesse\Documents\Documents\Games I have created\Python games\Guitar Memorization.py", line 46, in guessing
note = random.choice(notes not in guessed)
File "C:\Python33\lib\random.py", line 248, in choice
i = self._randbelow(len(seq))
TypeError: object of type 'bool' has no len()
我现在怎么能修好它?在
^{pr2}$感谢所有帮助我的人。在
您在猜测中没有将}内的重新分配在全局范围内可见。如果不这样,
other_string
标记为global,所以当您将它赋给guessing()
中的字符串时,它正在创建一个新的变量other_string
,它正好在guessing()
函数的作用域内。要解决此问题,请将global other_string
添加到guesing()
的顶部,使您在{other_string
在全局命名空间中仍被视为int,并且不能订阅int。在other_string
不是iterable对象。您可以将其初始化为other_string=[]
除此之外,{{{cd2>以外的任何一个{cd2>都应该使用
在您的
guessing()
方法中将其他的字符串声明为global
,然后您可以在guessing()
的主体中修改它print(guessing())
不会打印任何内容,您没有在您的guessing()
方法中返回任何值,您应该在末尾添加return guess
,并且它应该与外部if elif语句对齐。相关问题 更多 >
编程相关推荐