习题14 提示和传递

来源:互联网 发布:淘宝店铺运营规划书 编辑:程序博客网 时间:2024/06/11 02:44
</pre><pre>

from sys import argvscript,user_name = argvprompt = '> '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_namelikes = raw_input(prompt)print "Where do you live %s?"% user_namelives =raw_input(prompt)print "What kind of computer do you have?"computer = raw_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)

注意我们使用了

prompt = '> 'likes = raw_input(prompt)
这样的语句,这样在需要输入的时候就会自带一个 > 符号了

结果是这样的



========================================================================

附加练习:

3.再添加一个参数

比如我们可以添加一个,绰号(chuohao)

from sys import argvscript,user_name,chuohao = argvprompt = '> 'print "Hi %s %s,I'm the %s script."%(user_name,chuohao,script)print "I'd like to ask you a few questions."print "Do you like me %s?"% user_namelikes = raw_input(prompt)print "Where do you live %s?"% user_namelives =raw_input(prompt)print "What kind of computer do you have?"computer = raw_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)


有如下结果



现在我成为了 David风行者(David WindRunner) 了!!

0 0