代码
# Ex14 提示和传递
from sys import argv
script, user_name = argv
prompt = '>' # 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} computer. Nice.
""")
# 将用户提示符设置为变量prompt 这样就不需要在每次用到input时反复输入提示用户的字符了
# 而且,如果要将提示符修改成别的字符串,只要改一个位置就可以了 很方便
运行结果
注意指令里要包括全部的参数 不然就会报错