Tag: ack try = = Hand Stat Programs Erro objects not
1. Programs is composed of modules.
2. Modules contain statements.
3. Statements contain expressions.
4. Expressions Create and Process objects.
HandlingErrorsBy testing Inputs
"""
(1) Judging input
"""
whiletrue:reply=input('Enter Text:')
ifReply = ='Stop': Break elif notreply.isdigit ():Print('bad!'* 8)Else:Print(int (Reply) * * 2)Print('Bye')"""
(2) What if the input is not a number?
"" "# Method one
whiletrue:reply= Input ('Enter Text:')ifReply = ='Stop':Break
# if illegal str, execute except Try : num=Int (Reply)except:Print('bad!'* 8)Else:Print(NUM * * 2)Print('Bye')# Method Two whiletrue:reply= Input ('Enter Text:')ifReply = ='Stop': Break elif notReply.isdigit (): # If it's not a numberPrint('bad!'* 8)Else: # If the number num=Int (Reply)ifNum < 20:Print(' Low')Else:Print(NUM * * 2)Print('Bye')
[PyProj] Think in Python: