[PyProj] Think in Python:

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.