5200.6 User Input
input() 方法会暂停你的程序,等待用户输入。
在写input() 的时候,注意给用户清晰的输入提醒。
你可以使用字符串拼接的方式,输出多行提醒。
prompt = "If you share your name, we can personalize the messages you see."
prompt += "\nWhat is your first name? "
name = input(prompt)
print(f"\nHello, {name}!")input 接受的信息,python 都解析成 string. 如果要使用用户输入信息进行数学处理的话,需要使用 int()方法。
age = input("How old are you? ")
age = int(age)
age >= 18