新人求助!Python 代码报错“name not defined”
# print out the message for the player's choice
print 'the player chooses ' + player_choice
# convert the player's choice to player_number using the function name_to_number()
return name_to_number(player_choice)
# compute random guess for comp_number using random.randrangedef comp_number(c_number):def comp_number(number):
def comp_number():
return random.randrange(0,5)
# convert comp_number to comp_choice using the function number_to_name()
def comp_choice():
print 'the computer chooses '+ number_to_name(comp_number())
# compute difference of comp_number and player_number modulo five
if comp_number()-rpsls(player_choice) == 1:
print 'Computer wins!'
elif comp_number()-rpsls(player_choice) == 2:
print 'computer wins'
报错的是标红的这一栏, player_choice没有定义,但是我前面是def rpsls(player_choice)的呀,为什么还是显示没定义呢?谢谢各位
相关推荐
Python 解决execjs._exceptions.ProgramError: ReferenceError: document is not defined报错问题
今天用execjs调用JS时,发现报错execjs._exceptions.ProgramError: ReferenceError: document is not defined 如图: 错误类型:文档对象未定义,解决方法,定义对象即可,习惯性定义变量嘛 var document ;? emmmmmmmmmmmmmmm….不行的,继续报错 execjs._exceptions.ProgramError: TypeError: Cannot read property 'createElement' of undefined 若是报错:execjs._exceptions.Prog
Python中对错误NameError: name ‘xxx‘ is not defined进行总结
最近在使用python过重遇到这个问题,NameError: name 'xxx' is not defined,在学习python或者在使用python的过程中这个问题大家肯定都遇到过,在这里我就这个问题总结以下几种情况: 错误NameError: name 'xxx' is not defined总结情况一:要加双引号(" ")或者(' ')而没加情况二:字符缩进格式的问题情况三:`if __...
django执行命令 python manage.py startapp xxx报错os not defined问题(.pdf
django执行命令 python manage.py startapp xxx报错os not defined问题(
python3使用thrift操作hbase hbase-thirft报错解决
python连接hbase需要用到hbase-thirft类库,但是hbase-thirft只在python2下能正常使用,如果在python3下,会报错,主要有一下几个错误 except IOError, io: SyntaxError: invalid syntax ModuleNotFoundError: No module named 'ttypes' NameError:name ‘xrange’ is not defined 这几个都是python3和python2语法不兼容导致的,下载的包已经把这些错误结果了,在python下能正常使用
Python基础中所出现的异常报错总结
本篇文章介绍了Python基础中所出现的异常报错总结,这是Python日常所常见的错误,现在总结出来给大家。


