python基础:六,用户输入

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值