欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

《笨办法学python3-Learn Python 3 the HARD WAY》-习题11 提问

程序员文章站 2022-06-15 18:41:54
...

学习内容:

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

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

运行结果:
《笨办法学python3-Learn Python 3 the HARD WAY》-习题11 提问
知识点:
input()
在控制台输入内容后直接读取输入的内容
语法:input()
整数:x = int(input());
浮点数:y = float(input())。
input(“xxxx”),xxxx是在控制台提示、指示输入什么内容。
input(’> '):在需要出入的时候提示>,也可以作提示选择项。
例:(if的用法后面会再说,现在只关注input的用法)

print ("How much do you weigh?")
weight = input('> ')
print (f"So, you're {weight} heavy.")

print ("What color is your hair?")
hair = input('White or Black\n> ')
if hair == "White":
    print ("Oh! Very trendy!")
elif hair == "Black":
    print ("Oh! You are chinese? Nice!")
else:
    print ("Looks very nice.")

《笨办法学python3-Learn Python 3 the HARD WAY》-习题11 提问