Add if demo
This commit is contained in:
parent
aa074b6545
commit
ed8b74a8c6
24
0004/if.py
Normal file
24
0004/if.py
Normal file
@ -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")
|
||||||
Loading…
x
Reference in New Issue
Block a user