有人请帮我处理以下代码。除非用户输入了有效的输入,否则代码的目的是继续循环。
marks1 = int(input("Enter Marks1: "));
while(marks<0 or marks>100):
print("Please enter a valid input");
continue
marks2 = int(input("Enter marks2: "));
while(marks2<0 or marks2>100):
print("Please enter a valid input");
continue
marks3 = int(input("Enter marks3: "));
while(marks3<0 or marks3>100):
print("Please enter a valid input");
continue
但是当我运行程序时。它给出了连续输出:
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
"Please enter a valid number"
我可以知道代码中的问题是什么吗?
答案 0 :(得分:0)
我做的修正:
marks
而不是marks1
。continue
。这里没必要。固定代码(一节):
marks1 = int(input("Enter Marks1: "))
while marks1<0 or marks1>100:
print("Please enter a valid input")
marks1 = int(input("Enter Marks1: "))