"""
条件控制语句:
第一种语法:
if condition:
statement1
statement2
statement3
.......
如果if后边条件成立或者为True,才执行if中的语句
如果不成立,不执行
如果怎么样,我去做什么
condition: 条件,条件成立,或者条件不成立
if True:
print()
if False:
print()
data = 3
"""
corn = 1600
price = 1600
if corn >= price:
print("购买英雄猴子成功!!!")
score = 90
# if score >= 85 and score <= 100:
if 85 <= score <= 100:
# if False and True => if False
print("A")
"""
条件控制语句2:
if condition:
statement1
else:
statement2
else:其他, 否则
else: 代表了condition之外的情况
如果怎么样
否则怎么样
如果条件成立了,执行if中语句
如果条件不成立或者说是其他情况,则执行else里面的语句。
"""
corn = 1500
price = 1600
if corn >= price:
print("购买英雄猴子成功!!!")
else:
print("购买英雄失败,金币不足,请充值!!!")
"""
条件控制语句:
if condition1:
statement1
elif condition2: #elif ==> else if
statement2
elif condition3:
...........
elif conditionN
statementN
else:(可选)
statementN+1
==
if condition1:
statement1
else:
if condition2:
statement2
else:
if condition3:
statement3
"""
Python(condition_learning)
最新推荐文章于 2024-07-23 14:36:35 发布