第2课时:分支结构进阶———逻辑判断 教学目标:掌握 if/elif/else、and、or、not。 教学过程: 复习成绩等级判断。 新授闰年判断、逻辑组合。 练习:判断三角形、成绩等级。 分层:基础改错,提高独立写,挑战闰年+月份天数。 总结:条件要写完整。 代码实例: python score=int(input("请输入成绩:")) if score >90: print("A") elif score >80: print("B") elif score >60: print("C") else: print("D") python year=int(input("请输入年份:") if (year 4 ==0 and year 100 !=0)or year 400 ==0: print("闰年") else: print("平年") 易错点:=和=混淆;条件顺序错误。 分层实例: ·基础:判断奇偶数。 ·提高:判断三角形能否成立。 ·挑战:判断三角形是等边、等腰还是普通三角形。 python a int(input()) b int(input()) c int(input()) if a b c and a +c>b and b +c a: if a =b =c: print("等边三角形") elif a =b or a =c or b =c: print("等腰三角形") else: print("普通三角形") else: print("不能构成三角形") 课堂活动:条件接龙一每人说一个f条件,下一人补else。 易错提醒:=是赋值,=是判断;条件顺序不能乱。Python 第二课 · 代码合并版 1成绩等级.py — 成绩等级判断 score = int(input("请输入成绩:")) if score >= 90: print("A") elif score >= 80: print("B") elif score >= 60: print("C") else: print("D") 2闰年判断.py — 闰年判断 year = int(input("请输入年份:")) if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print("闰年") else: print("平年") 3.py — 三角形判断 a = int(input()) b = int(input()) c = int(input()) if a + b > c and a + c > b and b + c > a: if a == b == c: print("等边三角形") elif a == b or a == c or b == c: print("等腰三角形") else: print("普通三角形") else: print("不能构成三角形")