Detection in Python script app: Handling exceptions and triggering exceptions

Source: Internet
Author: User
Tags python script

#!/usr/bin/python
#coding: Utf-8
Try
X=int (Raw_input ("Please enter user name:"))
Print 3/x
Except Keyboardinterrupt:
Print "You have entered Crtl+c, please try again"
Except Eoferror:
Print "You have entered Ctrl+d, please try again"
Except ValueError:
Print "Not a number you entered"
Except Zerodivisionerror,e: #把自带报错存入变量
Print "Divisor cannot enter 0:", e #打印自带报错信息
Else
Print "No Problem" #不出错执行
Finally
Print "Game over" #出不出错都执行

#!/usr/bin/python
#coding: Utf-8
X=raw_input ("xxx Do you Love Me (y/n)?" ")
Try
If x!= ' y ':
Raise ValueError, "the answer is no, please try again"
Except Valueerror,e:
Print E
Else
print "OK"

Detection in Python script app: Handling exceptions and triggering exceptions

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.