【Python自学笔记】EX11-EX14 用户的输入

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_24994943/article/details/81938098
# ex11
# 获取输入input()
# 用end=' '来告诉print函数,不要以换行符作为结尾开始新的一行

print("How old are you?", end=' ')
age = input()
print("How tall are you?", end=' ')
tall = input()
print("How much do you weight?", end=' ')
weight = input()

print(f"So, you're {age} old, {tall} tall and {weight} heavy.")

# ex12
# 将要提示用户输入的文字放在input括号里面,本例子是上一个例子的重写,即与上一个例子输出一致

age = input("How old are you? ")
tall = input("How tall are you? ")
weight = input("How much do you weight? ")

print(f"So, you're {age} old, {tall} tall and {weight} heavy.")

# ex13
# 用命令行直接接收参数

from sys import argv
script, first, second, third = argv # 命令行执行时的输入应类似于python ex13.py One Two Three

print("The script is called:", script)
print("Your first variable is:", first)
print("Your second variable is:", second)
print("Your third variable is:", third)

# ex14
# 这是一个结合了argv和input两个输入的例子,类似于一个文字冒险游戏

from sys import argv
script, userName = argv
prompt = '> '

print(f"Hi {userName}, I'm the {script} script.")
print(f"I'd like to ask you a few questions.")
print(f"Do you like me {userName}?")
likes = input(prompt)

print(f"Where do you live {userName}?")
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.
""")

猜你喜欢

转载自blog.csdn.net/sinat_24994943/article/details/81938098
今日推荐