• 欢迎访问我的个人博客网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 如果您觉得本站对您有用,那么赶紧使用Ctrl+D收藏吧!
  • 相关内容持续完善中......

笨办法学python-习题4:变量(variable)和命名

Python hubin 1年前 (2018-02-07) 241次浏览 0个评论 扫描二维码

练习:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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_passengers_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 need to put about",average_passengers_per_car,"in each car."

习题:

1.报错:第8行变量名carpool_capacity误写为car_pool_capacity

2.为赋值语句添加注解

cars = 100

#将100赋值给cars

space_in_a_car = 4.0

#将4.0赋值给space_in_a_car

drivers = 30

#将30赋值给drivers

passengers = 90

#将90赋值给passengers

cars_not_driven = cars – drivers

#将变量cars的值减drivers的值的差赋值给cars_not_driven

cars_driven = drivers

#将变量drivers的值赋值给cars_driven

carpool_capacity = cars_driven * space_in_a_car

#将变量cars_driven的值乘space_in_a_car的值的积赋值给变量carpool_capacity

average_passengers_per_car = passengers / cars_driven

#将变量passengers的值除以cars_driven的值的商赋值给average_passengers_per_car


本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:笨办法学python-习题4:变量(variable)和命名
喜欢 (0)
hubin
关于作者:
头像
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址