exercise 14

from sys import argv

script, user_name = argv
# 提示符
prompt = '>'

print(f"Hi {user_name}, I'm the {script} script.")
print("I'd like to ask you a few questions.")
print(f"Do you like me {user_name}?")
likes = input(prompt)

print(f"Where do you live {user_name}?")
lives = input(prompt)

print("What kind of computer do you have?")
computer = input(prompt)

print(f"""
Alright, so you said {likes} about liking me.
You live in {lives}. Not sure where that is.
And you have a {computer}. Nice.
""")

练习

  1. Find out what the games Zork and Adventure were. Try to find a copy and play it.
  2. Change the prompt variable to something else entirely.
  3. Add another argument and use it in your script, the same way you did in the previous exercise withfirst, second = ARGV .
  4. Make sure you understand how I combined a """ style multiline string with the {} format activatoras the last print.

答案

from sys import argv
script, name = argv
dog = ">"

print("Hello {name}, I'm {script}.")
print(f"I'd like to ask some questions.")
print(f"Do you like {name}?")
likes = input(dog)

print(f"where do you live {name}")
home = input(dog)
print("What kind of computer do you have?")
computer_band = input(dog)
print(f"""
Alright, so you said {likes} about liking me.
You live in {home}. Not sure where that is.
And you have a {computer_band}. Nice
""")
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容