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

# 分支语句

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

原文:https://www.cnblogs.com/ericblog1992/p/11269486.html

你可能感兴趣的:(python分支判断语句)