Python 如何在输入特定输入之前一直问相同的问题
Python 如何在输入特定输入之前一直问相同的问题,python,Python,如上图所示,代码将不断请求标记并将其存储在变量中。在用户输入-1之前,它不会停止。然后将为平均标记输入的所有输入相加使用while循环 为True时: n=int(输入('请输入一个100分的分数:')) 如果n==-1: 打破 您需要这样做: while True: answer = int(float(input("please enter a mark out of 100: "))) #this way you keep asking while t
如上图所示,代码将不断请求标记并将其存储在变量中。在用户输入-1之前,它不会停止。然后将为平均标记输入的所有输入相加使用
while
循环
为True时:
n=int(输入('请输入一个100分的分数:'))
如果n==-1:
打破
您需要这样做:
while True:
answer = int(float(input("please enter a mark out of 100: ")))
#this way you keep asking while the answer doesn't match a condition
if answer < 0: #check if your objective has been completed
break #if condition matchese you stop the loop
#do something else
为True时:
答案=int(浮动(输入(“请在100中输入一个分数:”))
#这样,当答案与条件不匹配时,您可以继续提问
如果答案<0:#检查您的目标是否已完成
中断#如果条件匹配,则停止循环
#做点别的
right_answer = 'Potato'
while True:
answer = input("Put the Question here: ")
if answer == right_answer:
break
else:
print('More code')