# 7.1 函数input() 的工作原理
### 任务:让用户输入文本,把文本呈现给用户
Tell me something,and I will repeat it back to you:Hello everyone!Hello everyone!
message = input("Tell me something,and I will repeat it back to you: ")
print(message)
## 7.1.1 编写清晰的程序
变量 = input(参数:说明/提示)
name = input("please enter your name:")
print(f"\nHello,{name}!")
promp = "if you tell us who you are,"
promp += "\nWhat is you first name?"
name = input(promp)
print(f"\nHello,{name}!")
## 7.1.2 使用int() 来获取数值输入
age = input("How old are you? ")
age
age = input("How old are you? ")
age
age >18
age = input("How old are you? ")
age
age = int(age)
age >= 18
height = input("How tall are you,in inches? ")
height = int(height)
if height > 48 :
print("\nYou are tall enough to ride")
else:
print("\nYou are not enough to ride")
## 7.1.3 求模运算符
将两个数相除并返回余数
可利用这一点来判断奇偶数
4%3
5%3
6%3
7%3
Enter a number ,and I'll tell you if it's even or odd : 数字
The number 数字 is 偶数/奇数
number = int(input("Enter a number ,and I'll tell you if it's even or odd : "))
if number%2 == 0:
print(f"\nThe number {number} is even")
else:
print(f"\nThe number {number} is odd")
python基础:六,用户输入
于 2023-07-15 22:02:55 首次发布