写一个try ..except代码来解决这个问题 [英] Write a try..except code for this problem
本文介绍了写一个try ..except代码来解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题如下:
使用try重写您的付费程序,除非您的
程序处理非通过打印消息
并退出程序来优雅地输入数字。
我尝试过:
我尝试了几个样本,包括弱版if:
小时=输入('输入小时数' :')
Rate = input('Enter Rate:')
if(int(Hours)或int(Rate)< 1):
print('错误,请输入数字值')
解决方案
Python尝试除外 [ ^ ]
请参阅 8。错误和例外 - Python 3.7.3文档 [ ^ ]。
The question is as follows:
Rewrite your pay program using try and except so that your program handles non-numeric input gracefully by printing a message and exiting the program.
What I have tried:
I have tried several samples, including a weak if version: Hours = input('Enter Hours: ') Rate = input('Enter Rate: ') if (int(Hours) or int(Rate) < 1): print('Error, please enter a numeric value')
解决方案
Python Try Except[^]
See 8. Errors and Exceptions — Python 3.7.3 documentation[^].
这篇关于写一个try ..except代码来解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文