Day13

Day13：elif 语句

写下你的第一个 Elif 语句

# 使用elif条件语句
x, y = 5, 10
if x > y:
print("x is greater")
elif x < y:
print("x is less")


检查多个elif条件

# checking more than one elif conditional statement
x, y = 5, 10
if x > y:
print("x is greater")
elif (x + 10) < y: # checking if 15 is less than 10
print("x is less")
elif (x + 5) == y: # checking if 10 is equal to 10
print("equal")


条件中嵌套条件

# writing multiple conditionals within each other - multiple block levels
x, y, z = 5, 10, 5
if x > y:
print("greater")
elif x <= y:
if x == z:
print("x is equal to z") # resulting output
elif x != z:
print("x is not equal to z") # won't get hit


if语句对比elif语句

# testing output of two if statements in a row that are both true
# 在一行中测试两个都成立的if语句
x, y, z = 5, 10, 5
if x < y:

print("x is less")
if x == z:
print("x is equal")


# testing output of an if and elif statement that are both true
# 测试if和elif条件都成立时的输出
x, y, z = 5, 10, 5
if x < y:
print("x is less")
elif x == z:
print("x is equal to z")


x, y = 5, 10
if x > y:
print("greater")
try x < y:
print("lower")