'''
if条件判断
'''
age = input("请输入你的年龄:")
age_int = int(age)
if age_int < 18:
print("不向未成年人销售烟酒!")
else:
print("请付款!")
print("欢迎下次光临")
if 条件1:
逻辑代码1
else if 条件2:
逻辑代码2
else 条件3:
逻辑代码3
age = input("请输入你的年龄:")
age_int = int(age)
if age_int < 16:
print("未满16岁,太小了!")
elif age_int < 18:
print("不向未成年人销售烟酒!")
else:
print("请付款!")
print("欢迎下次光临")
fee = input("请缴费50:")
fee = int(fee)
if fee == 50:
gender = input("是男性吗?(y/n):")
if(gender == "y"):
print("先生,您好!")
else:
print("女士,您好!")
print("缴费成功!")
elif fee < 18:
print("不向未成年人销售烟酒!")
else:
print("金额不正确!")
# 打印数字1到100
num = 1
while num <= 10:
print(num)
num += 1
for 临时变量 in 序列:
序列中存在待处理元素则进入循环体执行代码
# 打印1到10十个数字
for i in range(1,11):
print(i,end="")
# break跳出它所在的整个循环
# 打印1到20的偶数
i = 1
while i <= 20:
if i % 2 == 0:
# 如果这个偶数能被10整除,则跳出循环。
if i % 10 == 0:
break
print(i)
i += 1
print("*************")
# while循环嵌套,break跳出内层循环
# 打印1到4四个数字,每个数字的上一行都打印与数字相同个数的星号
i = 1
while i < 5:
j = 0
while j < i:
if(j == 3):
break
print("*",end="")
j += 1
print("")
print(i)
i += 1
# continue 跳出本次while循环
i = 1
while i <= 20:
i += 1
if i % 2 == 0:
if i % 10 == 0:
continue
print(i)
print("**********")