欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python 分支语句 等值判断 逻辑运算符

程序员文章站 2022-04-29 21:08:24
# 分支语句age = 233if age < 18: print('您还未满18岁,禁止入内')elif age > 18 and age < 60: print("欢迎光临,年龄在18-60之间")else: print("欢迎光临,年龄大于60岁")weight = input('体重(kg) ......
# 分支语句
age = 233
if age < 18:
print('您还未满18岁,禁止入内')
elif age > 18 and age < 60:
print("欢迎光临,年龄在18-60之间")
else:
print("欢迎光临,年龄大于60岁")

weight = input('体重(kg): ')
height = input("身高(cm):")
#体重/ 身高的平方 pow(4,2) = 16
bmi = int(weight) / pow(float(height), 2)
print(bmi)

if bmi <= 18.4:
print('偏瘦')
elif bmi > 18.4 and bmi <=23.9:
print('正常')
elif bmi > 23.9 and bmi <= 27.9:
print('过重')
else:
print('肥胖')



# 等值判断
print(1 == 1.0) #true
print(1 == '1') #false
print(1 == int('1')) #true

# 逻辑运算符 优先级 not > and > or
a = 4 > 1 #true
b = 5 < 2 #false
c = 8 == 8 #true
d = 9 < 6 #false

print( a and b) #false
print( a and c) #true
print( a or b) #true
print( d or b) #false
print(not a) #false
print(not b) #true

r1 = a and b or c and not d
# a and b or c and true
# false or true
# true
print(r1) # true

r2 = (a and (not b or c)) and d
# (a and (true or c)) and d
# (a and true) and d
# true and false
# false
print(r2) # false