Python Learning Notes (15)-Exception handling

Source: Internet
Author: User

Tag: Money case Exception put trace color must be exception python

Money = input ('Enter how much money:') months= Input ('A few more months:')Try: Res=Calc (int (money), int (months))exceptZerodivisionerror as E:#if the code inside the try is wrong, go to the code inside the except .Traceback.print_exc ()#just the details of the output error .    Print('the number of months to repay cannot be less than 1'E#months input 0 o'clockexceptValueError as E:Print('input must be an integer,%s'%e#Money\months when a non-integer is enteredexceptException as E:#catch all the exceptions    Print('Unknown Error! %s'%e)Else:#go without error, else    Print('should also be%s per month'%Res)Print('===== Go this way, whether it's wrong or not!!! ')

Python Learning Notes (15)-Exception handling

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.