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