age = 17
if age < 18:
print("孩子,来这里的都是成年人!")
print("等你成年了再来!")
print("再等一年吧!")
例2
age = 19
if age < 18:
print("孩子,来这里的都是成年人!")
print("等你成年了再来!")
print("再等一年吧!")
print("孩子,两年了,又见面了。等什么呢?赶紧上车吧!")
例3
age = 19
if age < 18:
print("孩子,来这里的都是成年人!")
print("等你成年了再来!")
print("再等一年吧!")
print("骗你的。还等什么呢?赶紧上车吧!")
双向分支
if 条件表达式:
语句1
语句2
...
else:
语句3
语句4
...
补充:input()
括号中可以写入字符串,运行时执行到这一句,会在屏幕上显示该字符串
括号内的字符串常用于“友情提醒”
input() 能接受用户输入的内容并返回到程序
input() 返回的内容一定是字符串类型
name = input("What's your name?")
print("Welcome, " + name + " !")
例1
gender = input("Please enter your gender(male/female): ")
print("Your gender is: {0}".format(gender))
if gender == "male":
print("OK, next.")
else:
print("Welcome!")
例2
score = int(input("Please enter your score: "))
if score >= 90:
print("A")
if 80 <= score < 90:
print("B")
if 70 <= score < 80:
print("C")
if 60 <= score < 70:
print("D")
if score < 60:
print("I’m sorry!")