Python 学习笔记(判断语句)
作者:
Ac-Ciallo
,
2024-04-27 12:53:19
,
所有人可见
,
阅读 10
判断语句
a = int(input())
b = 5
if a >= b:
print("%d is >= 5" % a)
print("a is so big")
else:
print("%d is < 5" % a)
print("a is so small")
输出 a 的绝对值
if a >= 0:
print(a)
else:
print(-a)
找a,b,c的最大值
a,b,c = map(int,input().split())
if a > b:
if a > c:
print(a)
else:
print(c)
else:
if b > c:
print(b)
else:
print(c)
else if要写成 elif
a = int(input())
if a >= 80:
print("A")
elif a >= 70:
print("B")
elif a >= 60:
print("C")
else:
print("D")
pass空语句
# 如果a>=80就不执行任何动作,否则输出a
a = int(input())
if a >= 80:
pass
else:
print(a)
逻辑条件表达式
# and:并且 , or:或者 , not:非
# 优先级:not > and > or
# 判断闰年
year = int(input())
if year % 100 != 0 and year % 4 == 0 or year % 400 == 0:
print("yes")
else:
print("no")