Ture 和 False的测试
if语句 if_else语句 if-elif-else语句
# if语句基本用法
cars = ['bmw', 'audi', 'subaru', 'toyota']
for car in cars:
if car == 'bmw':
print(car.upper())
else:
print(car.title())
#
# 检查是否在列表里
banned_users = ['A', 'B', 'C']
user = "wenzheng"
if user not in banned_users:
print(user.title() + ", you can post a response if you wish ")
#
# 检查是否在列表里
game_active = True
can_edit = False
#
# 使用 == 返回结果 真为True
car = 'subaru'
print("Is car == 'subaru' ? I predict True")
print(car == 'subaru')
#
# 使用 == 返回结果 真为True
age = 12
if age < 4:
price = 0
elif age < 18:
price = 4
else:
price = 10
print("Your admission cost is $" + str(price) + ".")
# 动手试一试
alien_color = 'yellow'
if alien_color == 'green':
print("You get 5 points!")
elif alien_color == 'yellow':
print("You get 10 points!")
elif alien_color == 'red':
print("You get 15 points!")
alien_color = 'green'
if alien_color == 'green':
print("You get 5 points!")
elif alien_color == 'yellow':
print("You get 10 points!")
elif alien_color == 'red':
print("You get 15 points!")
alien_color = 'red'
if alien_color == 'green':
print("You get 5 points!")
elif alien_color == 'yellow':
print("You get 10 points!")
elif alien_color == 'red':
print("You get 15 points!")
# 5-8
lists = ['admin', 'Alice', 'wenzheng', 'Meng', 'Lihua']
for list_name in lists:
if list_name == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello " + list_name + ",thank you logging in again")
if len(lists) == 0:
print("We need to find some users!")
else:
n = len(lists)
del lists[-n:] # 大神的删除数列表所有元素的方法
print(lists)
print("We need to find some users!")