单分支判断
通过缩进来进行识别,if后需要加:
age=input("请输入年龄")
age=eval(age)
if age>18:
print("已成年")
双分支判断
if 条件:
xxxx
else :
xxxx
age = input("请输入年龄")
age = eval(age)
if age > 18:
print("已成年")
else:
print("未成年")
if嵌套
age = input("请输入年龄")
age = eval(age)
if age > 18:
print("已成年")
else:
if 0 <= age < 1:
print("婴儿")
if 1 <= age < 3:
print("儿童")
if 3 <= age < 18:
print("青少年")
else if
age = input("请输入年龄")
age = eval(age)
if age > 18:
print("已成年")
elif 0 <= age < 1:
print("婴儿")
elif 1 <= age < 3:
print("儿童")
elif 3 <= age < 18:
print("青少年")