[英]In python how can I take input from user and jump to a different line after taking input?
am new to python and was working on the following code (program to find average)我是 python 的新手,正在处理以下代码(查找平均值的程序)
sum=0
for i in range(1,9999):
n=int(input("Enter your number: "))
i+=1
sum=n+sum
a=input("Do you want to add more (Y/N): ")
if a=="Y" or a=="y":
continue
elif a=="N" or a=="n":
break
else:
print("Error: Incorrect choice")
i-=1
avg=sum/i
print(avg)
All good, but if the user inputs "Incorrect choice" how can I make it jump to the "if statement" where it asks the user again whether he/she wants to add more number?一切都很好,但是如果用户输入“不正确的选择”,我怎样才能让它跳转到“if 语句”,它会再次询问用户他/她是否想要添加更多数字? In structured programming I think "goto" or "label" can be used, but python is object oriented, how can I make it work here.
在结构化编程中,我认为可以使用“goto”或“label”,但是 python 是面向对象的,我如何让它在这里工作。 Please advice.
请指教。
there are several way you can use "while"有几种方法可以使用“while”
while a not in ["Y","y","N","n"]:
a=input("Do you want to add more (Y/N): ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.