Ptarget = int(input("What is your target amount of points to achieve?"))
while Ptarget != int:
print("You have not provided a valid input, please try again.")
Ptarget = int(input("What is your target amount of points to achieve?"))
如何使while循环起作用,通过在不破坏程序的情况下要求用户输入另一个输入(如果前一个不是整数)?
答案 0 :(得分:0)
使用例外
while True:
try:
Ptarget = int(input("What is your target amount of points to achieve?"))
break
except:
print("You have not provided a valid input, please try again.")