From ed8b74a8c6bd7d4bd1c4cacb480c868dfbbf8581 Mon Sep 17 00:00:00 2001 From: Henry Lin Date: Wed, 13 Aug 2025 10:41:45 +0800 Subject: [PATCH] Add if demo --- 0004/if.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 0004/if.py diff --git a/0004/if.py b/0004/if.py new file mode 100644 index 0000000..6b1d869 --- /dev/null +++ b/0004/if.py @@ -0,0 +1,24 @@ +# 判断是否成年 +age = 20 +if age >= 18: + print("您已经成年了!") + +""" 基础:编写一个if语句,如果变量number大于10,则打印“数字大于10”。 """ + +num = 15 +if num > 10: + print("数字大于10") + +""" 应用:给定两个变量score1和score2,编写一个if语句来比较它们,如果score1大于score2,则打印“第一个分数更高”。 """ + +score1 = 100 +score2 = 50 + +if score1 > score2: + print("第一个分数更高") + +""" 挑战:编写一个if语句,检查一个数字num是否是3的倍数且小于100。 """ +num = 99 +if num < 100: + if num % 3 == 0: + print(f"{num}是3的倍数且小于100") \ No newline at end of file