goodnumber = False
while not goodnumber:
try:
edgeone = int(input('Enter the first edge of the triangle:'))
if edgeone > 0:
print('thats a good number, thanks')
goodnumber = True
else:
print('thats not a number greater than 0, try again please')
except ValueError:
print('Thats not a number, try again please')
try:
value = int(raw_input("Enter your number:"))
if not ( value < 0 ):
raise ValueError()
except ValueError:
print "you must enter a number <0 "
else:
print value #or something else
我想你只想要数字大于0,还是要小于零?无论如何,你可以在while循环中使用try/except。在
对于python3,我认为您正在使用它?
希望这有帮助。在
对于这种情况,必须使用except处理程序:
这个问题在这里已经有了答案:Accepting only numbers as input in Python
你可以这样做。在
相关问题 更多 >
编程相关推荐