![](/img/trans.png)
[英]Why does greater than and unequal operators work even though only less than and equal operator has been overloaded
[英]Why does the loop start after I enter the first value for team A even though it's less than 15?
为什么在我为团队 A 输入第一个值后循环开始,即使它小于 15? 在我输入第一个值后,它不会 go 到下一个循环,我应该再次输入该值直到它达到 15。
team_a = int(input("Please enter the score for team A: "))
team_b = int(input("Please enter the score for team B: "))
team_a_score = 0
team_b_score = 0
Round = 0
total_score = 15
while total_score>team_a_score:
team_a_score+=team_a
if total_score<team_a_score:
break
print("the game is over")
break前应该有一个空格,你的意图是错误的! 更正了
team_a = int(input("Please enter the score for team A: "))
team_b = int(input("Please enter the score for team B: "))
team_a_score = 0
team_b_score = 0
Round = 0
total_score = 15
while total_score>team_a_score:
team_a_score+=team_a
if total_score<team_a_score:
break
print("the game is over")
现在您只输入一次值。
如果要在循环中输入值,则应如下所示:
team_a_score = 0
team_b_score = 0
Round = 0
total_score = 15
while total_score>team_a_score:
team_a = int(input("Please enter the score for team A: "))
team_b = int(input("Please enter the score for team B: "))
team_a_score+=team_a
if total_score<team_a_score:
break
print("the game is over")
为什么不询问循环内的输入?
team_a_score = 0
total_score = 15
while total_score > team_a_score:
team_a = int(input("Please enter the score for team A: "))
team_a_score += team_a
print("the game is over")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.