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