笨办法13参数、解包、变量_草稿

来源:互联网 发布:yii框架 商城源码 编辑:程序博客网 时间:2024/06/14 05:30

加分习题3:将 raw_input 和 argv 一起使用,让你的脚本从用户手上得到更多的输入。

from sys import argvscript, first, second, third = argv #试了一下,这里的第一个参数script可以随便改成啥,不影响运行结果'''print "The script is called:", scriptprint "Your first variable is:", firstprint "Your second variable is:", secondprint "Your third variable is:", third'''raw_input("The script is called: "), scriptraw_input("Your first variable is: "), firstraw_input("Your second variable is: "), secondraw_input("Your third variable is: "), third

不知道是不是这个意思,总觉得怪怪的,先这样后面再改!

运行结果如下,需要手动输入变量名:
这里写图片描述

【下班啦下班啦!!

==============下面重写!==============

from sys import argvscript, first, second, third = argvprompt = ">"print "please enter the script name:"script = raw_input(prompt)print "please enter the first variable:"first = raw_input(prompt)print "please enter the second name:"second = raw_input(prompt)print "please enter the third name:"third = raw_input(prompt)print """The script is called:%rThe first variable is:%rThe second variable is:%r The third variable is:%r""" % (script, first, second, third)

运行结果:
这里写图片描述

ps:但是怎么才能把引号去掉呢。。 埃玛以后再说吧!
来解答! 重新翻看了之前的第6课,只要把%r换成%s就没有引号啦!!


20170914 按照22课练习来复习

argv 和 raw_input()的区别:要求用户输入的位置不同。在命令行输入参数用argv.,在脚本执行的过程中输入参数用raw_input()

原创粉丝点击