如何編寫一個程序的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的輸入之後執行,但不否認的負輸入端。請幫助?
[詢問用戶進行輸入,直到它們得到有效的響應]的可能的複製(http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-給有效的答覆) – lmiguelvargasf
http://stackoverflow.com/a/42261523/6840615希望這可以解決您的問題 –