用户输入和while循环
函数input()
工作原理
函数input()接受一个参数——向用户显示的**提示(prompt)**或说明,让程序暂停运行,等待用户输入一些文本,在获取用户输入后,python将其赋给一个变量
message=input("Tell me something, and I will repeat it back to you:")
print(message)
若提示超过一行,可将提示赋给一个变量,再将该变量传递给函数input()
prompt="If you tell us who you are, we can personalize the messages you see."
prompt+="\nWhat is your first name?"
#第一行将消息的前半部分赋给变量prompt中,在第二行,运算符+=在前面赋给变量prompt的字符末尾附加一个字符串
name=input(prompt)
print(f'\nHello,{name}!')
int()获取数值输入
为避免python将输入解读为字符串,采用int()
height=input('how tall are you, in inches?')
height=int(height)
if height>=48:
print("\nyou're tall enough to ride!")
else:
prin