美文网首页
if/elif/else结构

if/elif/else结构

作者: huojusan | 来源:发表于2018-05-19 20:10 被阅读26次
    # -*- 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

    相关文章

      网友评论

          本文标题:if/elif/else结构

          本文链接:https://www.haomeiwen.com/subject/rhpadftx.html