如何编写一个程序的Python 3版本,该程序拒绝带有警告的负整数输入并且不允许它进入? 例如,Python 3检查输入的负数
print (' Hypothenuse ')
print ('______________________________________________')
while True:
L1=int(input('Value of L1:'))
L2=int(input('Value of L2:'))
if L1 >= 0:
if L1 ==0:
print("L1 Zero")
else:
print("L1 Positive Number")
else:
print("L1 Negative Number, Please Recheck Input")
if L2 >= 0:
if L2 ==0:
print("L2 Zero")
else:
print("L2 Positive Number")
else:
print("L2 Negative Number, Please Recheck Input")
h= pow(L1,2) + pow(L2,2)
print('Value of Hypot',h)
print('____________________________________________')
我的代码L1和L2的输入之后执行,但不否认的负输入端。请帮助?
+2
[询问用户进行输入,直到它们得到有效的响应]的可能的复制(http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-给有效的答复) –
+0
http://stackoverflow.com/a/42261523/6840615希望这可以解决您的问题 –