捕捉异常(3)

来源:互联网 发布:查看淘宝关键词搜索量 编辑:程序博客网 时间:2024/06/05 06:26
while True:    try:        x=input('Enter the first number:')        y=input('Enter the second number:')        value=x/y        print 'x/y is ',value    except:        print "Invalid input.Please try again."    else:        break


Enter the first number:1
Enter the second number:0
Invalid input.Please try again.
Enter the first number:
Invalid input.Please try again.
Enter the first number:'foo'
Enter the second number:'bar'
Invalid input.Please try again.
Enter the first number:baz
Invalid input.Please try again.
Enter the first number:10
Enter the second number:2
x/y is  5

0 0
原创粉丝点击