python中的提示和传递

这是学习python的第11课,主要学习了python中提示与传递,也就是通过input(),进行一些简单的人机对话。

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 question.")
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"""
All right,so you said {likes} about liking me.
You live in {lives}. Not sure where that is.
And you have a {computer} computer. Nice.
""")

 

运行结果:

python中的提示和传递

 

分析:

1、prompt = ‘> ’  这句代码是让  prompt 代替  >  ,便于后面代码的引用  。

2、likes = input(prompt)  这句代码是将我们在命令行写入的命令存到  likes 字符串中,便于后面代码的引用。