zoukankan      html  css  js  c++  java
  • 练习30--else和if

    一 代码及执行结果

    ex30.py

     1 people = 14
     2 cars = 15
     3 trucks = 10
     4 
     5 if cars > people:
     6     print("We should take the cars.")
     7 elif cars < people:
     8     print("We should not take the cars.")
     9 else:
    10     print("We can't decide.")
    11 
    12 if trucks > cars:
    13     print("That too many trucks.")
    14 elif trucks < cars:
    15     print("Maybe we could take the trucks.")
    16 else :
    17     print("We stil can't decide.")
    18 
    19 if people > trucks:
    20     print("Alright,let's just take the trucks.")
    21 else:
    22     print("Fine, let's stay home then.")

    执行结果:

    PS E:3_work4_python2_code_python2_LearnPythonTheHardWay> python ex30.py
    We should take the cars.
    Maybe we could take the trucks.
    Alright,let's just take the trucks.

    一些问题:

    1. 试着猜猜 elif 和 else 的作用是什么。
    在if的条件不满足的情况下进行下一步判断,并执行另外的操作
  • 相关阅读:
    浅谈python web三大框架
    Mysql异常
    格式化时间转换
    MySql存储日期为long型,判断时间大小
    Linux下部署项目
    excel
    Tomcate的启动问题
    计算时间差
    地图系的转换
    关于获取本机真实IP
  • 原文地址:https://www.cnblogs.com/luoxun/p/13292567.html
Copyright © 2011-2022 走看看