zoukankan      html  css  js  c++  java
  • python从入门到实践-5章if语句

    #!/user/bin/env python

    cars = ['audi','bmw','subaru','toyota']
    for car in cars:
    if car == 'bmw':
    print(car.upper())
    else:
    print(car.title())

    # == !=
    # <= >=
    # and or
    # in not in
    # True False
    # if-else
    # if-elif-elif-else # 选择一个执行
    requesed_toppings = ['mushrooms','green peppers','extra cheese']
    for requesed_topping in requesed_toppings:
    if requesed_topping == 'green peppers':
    print("Sorry,we are out of green peppers now.")
    else:
    print("Addin" + requesed_topping + ".")
    print(' Finished making your pizza!')


    # 确定列表不是空
    requesed_toppings = []
    if requesed_toppings:
    for requesed_topping in requesed_toppings:
    print("Adding" + requesed_topping + ".")
    print(" Finished making your pizza!")
    else:
    print("Are you sure you want a plain pizza?")

  • 相关阅读:
    类和对象
    使用JAVA理解程序逻辑
    类的有参
    1.人机猜拳
    类的无参方法
    类和对象
    Java解析XML
    集合框架一
    Java中的包
    继承
  • 原文地址:https://www.cnblogs.com/vwei/p/9879982.html
Copyright © 2011-2022 走看看