from random import choice
score_you = 0
score_com = 0
print('plaese select your direction !')
print('left front right')
def fof():
you = input()
print ('you select' + you)
l = ['left' 'front' 'right']
com = choice (l)
print('computer saved'+ com)
if you!=com:
score_you = score_you + 1
print ('good')
else:
score_com = score_com + 1
print ('bad')
fof()
fof()
fof()
fof()
if score_com < score_you:
print('congrdulation! you win')
else:
print('disapproint! you faild')python基础27课小游戏自编代码,错误如下:
"C:\Program Files\Python38\python.exe" C:/Users/23593/Desktop/.idea/list切片.py
plaese select your direction !
left front right
left
Traceback (most recent call last):
File "C:/Users/23593/Desktop/.idea/list切片.py", line 18, in <module>
you selectleft
computer savedleftfrontright
fof()
File "C:/Users/23593/Desktop/.idea/list切片.py", line 13, in fof
score_you = score_you + 1
UnboundLocalError: local variable 'score_you' referenced before assignment
求解!!!!!
作者: crossin先生 时间: 2019-11-25 00:20
函数里加上
global score_you