python 键盘输入负数_Python 3检查输入的负数

如何编写一个程序的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希望这可以解决您的问题 –


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部