程序:
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} computer. Nice.
""")
我有一個誤區,程序運行的時候我以為要運行兩個參數 python? .\ex14.py 2 3,其中2和3是我要輸入的參數,結果發現顯示報錯。
我改成python? .\ex14.py 2 就可以,原來.\ex14.py 也會作為一個變量。