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

# 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.
""")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值