重拾python 三十

来源:互联网 发布:人工智能读后感 编辑:程序博客网 时间:2024/04/29 09:52

接下来看看,if,else和elif,ex30.py:

#!/usr/bin/python# -*- coding: utf-8 -*-people = 30cars = 40trucks = 15if 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 trucks > cars:    print "That's too many trucks."elif trucks < cars:    print "Maybe we could take the trucks."else:    print "We still can't decide."if people > trucks:    print "Alright, let's just take the trucks."else:    print "Fine, let's stay home then."

运行后:

We should take the cars.
Maybe we could take the trucks.
Alright, let’s just take the trucks.

0 0
原创粉丝点击