exercise 14

作者: 不娶名字 | 来源:发表于2017-12-31 18:23 被阅读0次
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
""")

相关文章

网友评论

    本文标题:exercise 14

    本文链接:https://www.haomeiwen.com/subject/aweagxtx.html