习题 30 else 和 if

习题 30 else 和 if

# ex30.py

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."

结果:

$ python ex30.py
We should take the cars.
Maybe we could take the buses.
Alright, let's just take the buses.

Python 的规则是,只要一行以冒号(:)结尾,它接下来的内容就应该有缩进。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 习题0:准备工作 总有一天你会听到有程序员建议你使用 Mac OSX 或者 Linux。如果他喜欢字体美观,他会告...
    KennyP0618阅读 6,740评论 0 1
  • 个人学习批处理的初衷来源于实际工作;在某个迭代版本有个BS(安卓手游模拟器)大需求,从而在测试过程中就重复涉及到...
    Luckykailiu阅读 10,289评论 0 11
  • 前言 ||| 第二章 使用ArcPy编写脚本 Python支持大部分在其他语言中出现的编程结构。在本章内容中,我们...
    muyan阅读 90,650评论 10 55
  • 梅子涵的《绿光芒》篇篇都是回忆,几十年前的老记忆了。如《童话》,《火车》,《吃饭》,《看望》,《浪漫》,《编辑》,...
    一颗丹心_dyg阅读 3,122评论 0 2
  • 首先这不是讲男女感情的故事。 我是个失败的人,姑且这么定性,从高中到大学,一个经常是被调侃的人且总是被负能量占据,...
    8c816799bc41阅读 1,769评论 0 0

友情链接更多精彩内容