0
sp = int(input("the dp is $"))
print(sp)
while True: #make sure they only put number
try:
int(sp)
except ValueError:
try:
float(sp)
except ValueError:
print("This is not a number. Please put a valid price.")
print("Please enter a valid number")
#This is to ensure that the customer is entering a valid variable, not too high or low
if sp <=100: print("Your price is too low. Please enter a higher and valid price.")
if sp >=10000: print("Your price is too high. Please enter a lower and valid price")
當我嘗試放入過高或過低數字時,消息錯誤有效,但如果輸入字母,程序會報錯。ValueError:對於int()以10爲基數的無效文字:
你會得到哪個錯誤,什麼是完整的回溯?你怎麼看到最後兩行:你的'while'循環無法結束。 –
是的,因爲你正在使用'sp = int(input(「the dp is $」)',讓你的整個'while True'循環變得毫無意義,除去調用'int',這就是循環和try '是! –