笨方法学Python-习题14-提示和传递

本习题中使用argv和input,继续讨论和用户交互的话题。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sys import argv

script, user_name = argv
prompt = '> '

print(f"Hi {user_name}, I'm the {script} script.")
print(f"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(f"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.
""")

运行下,仔细品品是如何交互的。

ex14_运行结果

这道习题中依旧是问题三连,你喜欢Zed吗?Zed住哪里啊?你的电脑型号是什么?用户依次输入答案,最后再输出一段上述3个问题的总结。

总结

  1. 继续加深由argv和input组成的交互程序的理解。

你可能感兴趣的:(笨方法学Python-习题14-提示和传递)