Files
DailyChallenge_ProgrammingD…/Day_6/README.md
T
2026-08-22 01:09:26 +08:00

66 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Day_6 · 条件判断:让程序做决定
> 预计耗时:20~30 分钟
> 后端要根据不同情况做不同处理(参数合法就通过,不合法就报错)——这就是 `if`。
## 今日知识点
- `if 条件:` / `elif 条件:` / `else:`(注意冒号和缩进)
- 比较运算符:`>` `<` `>=` `<=` `==` `!=`
- `int(input(...))`:把键盘输入转成整数再比较
## 先学(教程)
- 菜鸟教程("条件控制"一节):https://www.runoob.com/python3/python3-conditional.html
- B站黑马教程(看讲"if 判断"的几集):https://www.bilibili.com/video/BV1qW4y1a7fU/
## 任务(后做)
新建 `day6.py`:
1. 年龄判断程序:
```python
age = int(input("请输入你的年龄:"))
if age < 18:
print("未成年")
elif age < 60:
print("成年")
else:
print("老年")
```
分别输入 `15`、`20`、`70` 测试三种结果。
2. **进阶(加分)**:成绩评级——输入分数(0~100 整数),
`>=90` 打印"优秀",`>=60` 打印"及格",否则打印"不及格"。
用 `if / elif / else` 写完,测 `95`、`75`、`50` 三个分数。
> 提示:缩进必须是统一的(Tab 或 4 空格),混用会报错——这是新手最常见的坑。
## 完成标准
- [ ] 三个年龄输入分别输出"未成年 / 成年 / 老年"
- [ ] 能说出 `elif` 和连续多个 `if` 的区别(试想:都用 if 会怎样?)
- [ ] (进阶)成绩评级三档正确
**提交方式**:把 `day6.py` 代码贴在当日工单评论里。
## 参考解答(先做再看)
```python
age = int(input("请输入你的年龄:"))
if age < 18:
print("未成年")
elif age < 60:
print("成年")
else:
print("老年")
# 进阶
score = int(input("请输入分数:"))
if score >= 90:
print("优秀")
elif score >= 60:
print("及格")
else:
print("不及格")
```