新人求助!Python 代码报错“name not defined”

云小楼 云小楼 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
def rpsls(player_choice):
# 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

weixin_38508126

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下能正常使用

峰哥csdn

Python基础中所出现的异常报错总结

本篇文章介绍了Python基础中所出现的异常报错总结,这是Python日常所常见的错误,现在总结出来给大家。

weixin_38665668
评论 3
收藏 已收藏
分享
返回顶部
云小楼
脚本语言 37,738 成员 34,208 内容