【发布时间】:2017-08-29 20:22:42
【问题描述】:
目前正在搞乱一个梦幻足球程序,要求用户首先输入 10 名球员姓名并将其添加到一个列表中,然后为每个球员输入不同变量的值,如进球、进球助攻等。第一个问题是“他们参加比赛了吗?”
如果答案是否定的,那么我将尝试跳过以下问题并跳转到下一个玩家,我一直在尝试使用 continue,但它只是循环并继续向第一个玩家询问第一个问题。
playerList=[]
def Playeradd():
playerList.append(item)
def Playercreate():
global item
item = raw_input("Enter Player name: ")
Playeradd()
[Playercreate()for _ in range (5)]
print
print "You have selected", len(playerList), "players for your squad, Your selected squad is.."
#print playerList
for item in playerList:
print item
player =Playercreate
scorecheck=[]
x=0
totalscore=0
def pointsaward():
global scorecheck, totalscore
y=1
player=y
x=0
while x < 5:
print
print "Please enter score for ", playerList[x]
print
play = raw_input(" Did he play the match (yes or no?) ")
if play == "yes":
play1=2
else:
play1=0
goalS= int(raw_input(" Did he score, if so how many?"))
goalS=goalS*5
goalA= int(raw_input(" How many assists?"))
goalA=goalA*3
motm= raw_input(" Did he win man of the match (yes or no?) ")
if motm == "yes":
motm1=5
else:
motm1=0
yelC=raw_input(" Did he recieve a yellow card (yes or no?) ")
if yelC == "yes":
yelC1= -1
else:
yelC1=0
redC=raw_input(" Did he recieve a red card (yes or no?) ")
if redC == "yes":
redC1= -5
else:
redC1=0
PenM=raw_input(" Did he miss a peno(yes or no?) ")
if PenM == "yes":
PenM1= -3
else:
PenM1=0
playerpoint1= play1+goalS+goalA+yelC1+redC1+PenM1
PlayerandScore= [playerList[x],playerpoint1,]
scorecheck.append(PlayerandScore)
totalscore+= playerpoint1
# print "This player has scored a total of ", PlayerandScore, " this week "
x+= 1
y+= 1
print "This player has scored a total of ", PlayerandScore, " this week "
print
pointsaward()
抱歉,如果不清楚,那么对于玩家 1 如果第一个问题的答案是否定的,那么就没有必要问关于玩家的以下问题,因为他不会玩。所以我希望它跳过以下问题并开始询问列表中玩家 2 的输入。
【问题讨论】:
-
也许你想
break退出循环? -
请发布完整代码。很难理解“但它只是循环并继续向第一个玩家询问第一个问题”。代码应该做什么?
-
我会将你所有的 IF 语句移到第一个 IF 下。这样,如果是,则执行所有其他 IF。如果不是,则返回问题。
标签: python list loops conditional-statements