Stupid way to learn Python exercises 13 and 14

Source: Internet
Author: User

Original question:

1  fromSysImportargv2 3Script, first, second, third =argv4 5 Print "The script is called:", Script6 Print "Your First variable is:", First7 Print "Your Second variable is:", Second8 Print "Your Third variable is:", third

Note here: the argv---Equivalent to the $ parameter in the shell, parameter 1, parameter 2 = argv #之后参数的引用就和这个先后顺序有关了

In the third article of the study drill it gives: Combine raw_input with argv to make a script this gets more input from a user. Requires a script to be created in conjunction with Raw_input and argv

In the case of trying to use exercise 13 and previous exercises as material to change the program failure, learn the Python record with a stupid method--exercise 12-14 is mainly pydoc usage, raw_input,argv and a certain degree of rewriting, the code is as follows:

1  fromSysImportargv2 3Script, user_name = argv4 5 Print "My name is%s, and you know I am the%s script."%(user_name, script)6 7like = Raw_input ("Like me?")8Age = Raw_input ("How is old is you ?")9 Ten Print """ One  A OK, you said%r me very much. You is%r years old. -  - """% (like, age)

The results are as follows: (performed under PowerShell)

Ps:

1. Pydoc in Windows usage, must go into the Python installation directory, execute python-m pydoc raw_input; (Of course you can replace the raw_input with other modules, such as Open, OS,)

Here is the exercise code for Exercise 14:

1  fromSysImportargv2 3Script, user_name =argv4prompt ='>'5 6 Print "Hi%s, I ' m the%s script."%(user_name, script)7 Print "I ' d like-to-ask you a few questions."8 Print "Do you like me%s?"%user_name9Likes =raw_input (Prompt)Ten  One Print "Where Do you live%s?"%user_name Alives =raw_input (Prompt) -  - Print "What kind of computer does you have?" theComputer =raw_input (Prompt) -  - Print""" - alright, so-said%r about liking me. + You live in%r. Not sure where the IS. - And you have a%r computer. Nice. + """% (likes, lives, computer)

Operation Result:

Rewrite code:

1  fromSysImportargv2 3Script, user_name =argv4 5 Print "Hi,%s, I ' m the%s script."%(user_name, script)6 Print "I ' d like-to-ask you a few questions."7 8Likes = Raw_input ("Don't like me%s?\n>"%user_name)9lives = Raw_input ("Where Do you live%s?\n>"%user_name)TenComputer = Raw_input ("What kind of computer does you have?\n>") One  A Print """ - alright, so-said%r about liking me. - You live in%r. Not sure where the IS. the And you have a%r computer. Nice. - """% (likes, lives, computer)

The result is the same, and the map is no longer here.

Stupid way to learn Python exercises 13 and 14

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.