码迷,mamicode.com
首页 > 其他好文 > 详细

练习30--else和if

时间:2020-07-13 13:46:48      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:条件   car   decide   truck   情况下   int   作用   下一步   --   

一 代码及执行结果

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_work\4_python\2_code_python\02_LearnPythonTheHardWay> python ex30.py
We should take the cars.
Maybe we could take the trucks.
Alright,lets just take the trucks.

一些问题:

1. 试着猜猜 elif 和 else 的作用是什么。
在if的条件不满足的情况下进行下一步判断,并执行另外的操作

练习30--else和if

标签:条件   car   decide   truck   情况下   int   作用   下一步   --   

原文地址:https://www.cnblogs.com/luoxun/p/13292567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!