Python Learning 03--design, related to input

Source: Internet
Author: User

Stupid way to learn Python 36th, I wrote the following code:

 fromSysImportExitdefrule ():Print "congratulations! you are made the right choice."    Print "But is also a terrible choice."    Print "Abide by the contract of the Devil."    Print "Input your choice: \ n 1.dog \ 2.cat \ n 3. Panda"Next= Raw_input (">")    ifnext.isdigit (): Next1=Int (next)ifNext1 = = 1:             Print "Don ' t quarrel with me!"        elifNext1 = = 2:             Print "Remember, good boyfriend won ' t quarrel with his girlfriend!"        elifNext1 = = 3:             Print "Remember, don ' t quarrel with me!!!!!!!"         Else:             Print "Input a number in range (1,4)!"            Else:        Print "Please input a number"exit (0)defstart ():Print "Do I want to be my boyfriend?"    Print "input ' yes ' or ' no '"Next= Raw_input (">")    ifNext = ="Yes": Rule ()elifNext = ="No":        Print "How Dare you!"    Else:        Print "You don ' t even know the rule, bye bye"Start ()

This is used Raw_input (">"), the following code is input (">")

 fromSysImportExitdefrule ():Print "congratulations! you are made the right choice."    Print "But is also a terrible choice."    Print "Abide by the contract of the Devil."    Print "Input your choice: \ n 1.dog \ 2.cat \ n 3. Panda"Next= Input (">")    ifNextinchRange (1,4):                ifNext = = 1:             Print "Don ' t quarrel with me!"        elifNext = = 2:             Print "Remember, good boyfriend won ' t quarrel with his girlfriend!"        Else:             Print "Remember, don ' t quarrel with me!!!!!!!"            Else:        Print "Please input a number in range (1,4)"exit (0)defstart ():Print "Do I want to be my boyfriend?"    Print "input ' yes ' or ' no '"Next= Raw_input (">")    ifNext = ="Yes": Rule ()elifNext = ="No":        Print "How Dare you!"    Else:        Print "You don ' t even know the rule, bye bye"Start ()

Note:

1. Inside the first code: NEXT = Raw_input (">"), meaning that whatever you enter is the type of the string, so add the following sentence next1 = Int (next) to the number to be judged.

2. Inside of the second code: Use next = input (">"), so do not next.isdigit (): Because this is the judgement of the string (see the previous section), here the words can be directly used next in range (1,4):, However, it should be noted that when you run the script, if you enter a string, you want to use "" quotation marks, otherwise the syntaxerror will appear.

3. Both functions can receive a string, but raw_input () directly reads the console input (any type of input it can receive). For input (), it wants to be able to read a valid Python expression, that is, you must enclose it in quotation marks when you enter a string, or it will throw a syntaxerror.

Python Learning 03--design, related to input

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.