简体   繁体   English

为什么在我为团队 A 输入第一个值后循环开始,即使它小于 15?

[英]Why does the loop start after I enter the first value for team A even though it's less than 15?

Why does the loop start after I enter the first value for team A even though it's less than 15?为什么在我为团队 A 输入第一个值后循环开始,即使它小于 15? After I enter the first value it doesn't go to the next loop where I am supposed to enter the value again until it reaches 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")

there should be a space before break, your intention was wrong! break前应该有一个空格,你的意图是错误的! Corrected it更正了

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")

Now you enter values only one time.现在您只输入一次值。
If you want to enter values in loop it should look like this:如果要在循环中输入值,则应如下所示:

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")

Why don't you ask the input inside your loop?为什么不询问循环内的输入?

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.

相关问题 为什么即使只有小于等于等号运算符被重载,大于和不等号运算符为何仍起作用 - Why does greater than and unequal operators work even though only less than and equal operator has been overloaded While 循环给出的值等于,即使它明确声明“小于”而不是“小于或等于” - While loop gives values equal to, even though it explicitly states 'less than' not 'less than or equal to' 进程在我调用 function 后启动,即使我尝试先启动进程 - Process starts after I call a function even though I try to start the process first 为什么即使我输入了与列表中的字符串匹配的正确字符串,if-else 语句中的条件也永远不会满足? - Why does the condition within the if-else statement never satisfy even though I enter the right string that matches the string in the list? 为什么我的计数器不更新,即使我在每个循环中都添加了一个? - Why does my counter not update even though I am adding one on every loop? 为什么即使满足条件也没有执行循环? - Why does the loop not get executed even though the conditions are satisfied? 为什么我会收到“ValueError:NaTType 不支持 strftime”,即使它不为空? - Why do I get 'ValueError: NaTType does not support strftime' even though it's not empty? 为什么我的 pygame 说它没有初始化,即使我初始化了它? - Why does my pygame say it's not initialized even though I initialized it? 为什么第二个循环中的 i 比用户给定的输入少 1? - Why does the i in second loop counts as 1 less than the given input by the user? 为什么这会产生一个断言错误,即使它正是所教的? - Why does this produce an assertionerror even though it's exactly what was taught?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM