python(4)

传递参数argv

'''
#脚本运行的时候需要传入3个参数 1st 2nd 3rd
#coding=utf-8
#python 引入模块的方法
from sys import argv
script,first,second,third = argv
print ("the script is called:",script)
print ("your first variable is:",first)
print ("your second variable is:",second)
print ("your third variable is:",third)
'''
#脚本运行的时候需要输入一个参数如: python 4.py zl
#提示和传递,input和argv结合
from sys import argv
script,user_name=argv
prompt='>'
print ("hi %s,I'm the %s script"%(user_name,script))
print ("I'd like to ask you a few questions")
print ("Do you like me %s?"%user_name)
likes=input(prompt)
print ("where do you live %s?"%user_name)
livers =input(prompt)
print ("what kind of computer do you have?")
computer =input(prompt)

print ("""
Alright,so you said %r about liking me.
You live in %r.Not sure where that is.
And you have a %r computer.Nice.
"""%(likes,livers,computer))

  

posted on 2017-12-17 15:24  never1211  阅读(121)  评论(0编辑  收藏  举报

导航