这是我自己学习的答案,会尽力写的比较好。还望大家能够提出我的不足和错误,谢谢!
文中例题:
代码:
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 = raw_input(prompt)
print "Where do you live %s?" % user_name
lives = raw_input(prompt)
print "What king 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)
运行结果:
加分习题:
1、查到Zork是一款文字类的游戏,而Adventure我没有查到,有机会会玩一下的。
2、prompt = '--- '
运行结果:
3、代码:
from sys import argv
script, user_name, user_appearance = argv
prompt = '--- '
print "Hi %s, I'm the %s %s script." % (user_appearance, user_name, script)
print "I'd like to ask you a few questions."
print "Do you like me %s %s?" % (user_appearance, user_name)
likes = raw_input(prompt)
print "Where do you live %s %s?" % (user_appearance, user_name)
lives = raw_input(prompt)
print "What king 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)
运行结果:
4、嗯!