5.18-笨办法学python-习题14

有了习题13的基础,习题14就不是问题了。

这一节主要是一个简单的提示符。提示符就是像">"这个的东西,因为我们之前用input的时候,它是用来让用户输入的,可是平常人并不知道这个时候要输入,所以在这一节我们设置一个提示符,其实是一个很简单的操作

贴上代码:

from sys import argv

script,user_name=argv
prompt='>'  #用户提示符>,如果不设置的话就没有>这个,直接空白一行

print ("H1 %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)
lives=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 ,lives ,computer))

前面还是运用了argv,现在很好理解了吧(argv的具体内容可以看我的前一篇文章~)

后面就是普通的print,只不过在input()时候,增加了prompt。需要注意的是,prompt=>,这样就可以直接利用prompt,而不要用三次>啦~

猜你喜欢

转载自www.cnblogs.com/daxixixixi/p/9054584.html