def Q7():
names=['ben','thor','zoe','kate'] #the list of names
Max = 4
found=False
Splayer = input("What plaer are you looking for? ")
while found == False and current <= Max:
if names[current]== Splayer:
found = true
else:
current = current+1
if found == True:
print('yes, they have a top')
else:
print('no,they do not have a top score')
这是一个程序要求我执行以下操作:找到播放器名称并根据用户输入打印出一个输出但是当我运行它时找到= = False和当前&lt; = Max: UnboundLocalError:局部变量&#39; current&#39;在分配之前引用 我如何让它正常工作
答案 0 :(得分:2)
def Q7():
names=['ben','thor','zoe','kate'] #the list of names
Max = 4
found=False
Splayer = input("What plaer are you looking for? ")
current = 0;
while found == False and current < Max:
if names[current]== Splayer:
found = True
current = current+1
if found == True:
print('yes, they have a top')
else:
print('no,they do not have a top score')
current
声明为0。True
不是true
答案 1 :(得分:0)
def Q7():
names=['ben','thor','zoe','kate'] #the list of names
Max = 4
found=False
current = 0
Splayer = input("What plaer are you looking for? ")
while found == False and current <= Max-1:
if names[current]== Splayer:
found = True
else:
current = current+1
if found == True:
print('yes, they have a top')
else:
print('no,they do not have a top score')
答案 2 :(得分:0)
tobias_k是对的。你真正想要的是:
names = ['ben', 'thor', 'zoe', 'kate']
player = input("What player are you looking for? ")
if player in names:
print("Yes, they have a top score.")
else:
print("No, they don't.")