if/elif/else结构

2018-05-19  本文已影响26人  huojusan
# -*- coding: utf-8 -*-
# @Author: yt
# @Date:   2018-05-19 19:58:01
# @Last Modified by:   yt
# @Last Modified time: 2018-05-19 20:01:58

people = 30
cars = 40
buses = 15

if cars > people:
    print "We should take the cars."
elif cars < people:
    print "We should not take the cars."
else:
    print "We can't decide."

if buses > cars:
    print "That's too many buses."
elif buses < cars:
    print "Maybe we could take the buses."
else:
    print "We still can't decide."

if people > buses:
    print "Alright, let's just take the buses."
else:
    print "Fine,let's stay home then."

运行结果如下: 图1
上一篇下一篇

猜你喜欢

热点阅读