我正在编写一个程序,将3名玩家及其分数存储在列表中,然后在最后打印出来 . 简单的东西真的,但是我试图从一个名为playerscore()的函数中调用玩家得分的值,这会阻止你输入得分> 5 .
当你使用正确的值运行它时,这工作正常,但是如果输入的值不正确> 5则会再次启动playercore函数并允许输入新值但返回“None”
teamlist = []
def playercreator():
counter=0
while counter < 3:
name = playername()
score = playerscore()
print(score) #check - this one goes wrong when returned after the if/else in playerscore()
teamlist.append(name+" "+str(score))
counter = counter + 1
def playername():
name=input("What name do you want for your player?\n")
return (name)
def playerscore():
global teamtotal
score=input("input score?\n")
print(score) #check
if int(score)>5:
print("Your attack score must be between 0 and 5")
print(score) #check
playerscore()
else:
return int(score)
playercreator()
for x in teamlist:
print(x)
例如,这些是输入和输出:
What name do you want for your player?
p1
input score?
3
What name do you want for your player?
p2
input score?
6
Your attack score must be between 0 and 5
input score?
5
What name do you want for your player?
p3
input score?
2
p1 3
p2 None
p3 2
我觉得有一些显而易见的东西让我失踪 . 谁能指出我正确的方向?