廖雪峰网站:学习python基础知识—判断(三)

时间:2023-03-08 15:12:18
廖雪峰网站:学习python基础知识—判断(三)

一、判断

1、条件判断

age = 18
if age >= 18:
print('your are is', age)
print('adult') age = 3 if age >= 18:
print('your are is', age)
print('adult') elif age >= 6:
print('your are is', age)
print('Sarah') elif age >= 3:
print('your are is', age)
print('Jack') else:
print('your are is', age)
print('mike') # 注意:
# input()返回的是字符串
# 必须通过int()将字符串转换为整数
# 才能用于数值比较:
age = int(input('Input your age:'))
if age >= 18:
print('your are is', age)
print('adult') elif age >= 6:
print('your are is', age)
print('Sarah') elif age >= 5:
print('your are is', age)
print('Jack') else:
print('your are is', age)
print('mike')