《“笨办法”学python3》Ex 4

知识点:

变量赋值,直接:名+=+值

==用于检查两边是否相等,要与=区分.

程序:

#车数
cars = 100
#每车容量
space_in_a_car = 4.0
#司机数
drivers = 30
#乘客数
passengers = 90
#空车数
cars_not_driven = cars - drivers
#可用车数
cars_driven = drivers
#总容纳量
carpool_capacity = cars_driven * space_in_a_car
#平均每车应搭载乘客数
average_passangers_per_car = passengers / cars_driven

print("There are",cars,"cars available. ")
print("There are only", drivers, "drivers available. ")
print("There will be",cars_not_driven,"empty cars today. ")
print("We can transport",carpool_capacity,"people today. ")
print("We have",passengers,"to carpool today. ")
print("We neeed to put about",average_passangers_per_car,"in each car. ")

输出:

PS C:\Users\xue weiruan\github> python ex4.py
There are 100 cars available.
There are only 30 drivers available.
There will be 70 empty cars today.
We can transport 120.0 people today.
We have 90 to carpool today.
We neeed to put about 3.0 in each car.
PS C:\Users\xue weiruan\github>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
笨办法 Python (第三版) 欢迎阅读《笨办法 Python》第三版。本书中译本发布于 https://learn-python-the-hard-way-zh_cn-translation.readthedocs.org 英文原版地址为 http://learnpythonthehardway.org/book/ Contents: 前言:笨办法更简单 习题0:准备工作 习题1:第一个程序 习题2:注释和井号 习题3:数字和数计算 习题4:变量(variable)和命名 习题5:更多的变量和打印 习题6:字符串(string)和文本 习题7:更多打印 习题8:打印,打印 习题9:打印,打印,打印 习题10:那是什么? 习题11:提问 习题12:提示别人 习题13:参数、解包、变量 习题14:提示和传递 习题15:读取文件 习题16:读写文件 习题17:更多文件操作 习题18:命名、变量、代码、函数 习题19:函数和变量 习题20:函数和文件 习题21:函数可以返回东西 习题22:到现在你到了哪些东西? 习题23:读代码 习题24:更多练习 习题25:更多更多的练习 习题26:恭喜你,现在可以考试了! 习题27:记住逻辑关系 习题28:布尔表达式练习 习题29:如果(if) 习题30: Else和If 习题31:作出决定 习题32:循环和列表 习题33: While循环 习题34:访问列表的元素 习题35:分支和函数 习题36:设计和调试 习题37:复习各种符号 习题38:列表的操作 习题39:字典, 可爱的字典 习题40:模块、类、对象 习题41:物以类聚 习题42:对象、类、以及从属关系 习题43:来自Percal 25号行星的哥顿人(Gothons) 习题44:继承 (Inheritance) VS合成(Composition) 习题45:你来制作一个游戏 习题46:一个项目骨架 习题47:自动化测试 习题48:更复杂的用户输入 习题49:创建句子 习题50:你的第一个网站 习题51:从浏览器中获取输入 习题52:创建你的web游戏 下一步 老程序员的建议

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值