python_chapter_5

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!")

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值