【发布时间】:2012-09-20 11:46:57
【问题描述】:
我是这里的python新手。 我一直在用“Learning Python the hard way”来学习,但我遇到了一个问题 exercise 4, extra credit, question 1.
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."
我为space_in_a_car 使用了 4.0,但这有必要吗?为什么在这种情况下使用 4.0 而不是 4?
我希望大家能帮我解释一下原因。
【问题讨论】:
-
也许你应该告诉我们你的问题是什么。
-
请发布问题的文本,并向我们展示您到目前为止所做的尝试。
-
我不认为对新用户的第一个问题投反对票是好的,试着多理解一点。有人建议如何改进这个问题,所以请给它一些时间。
-
您应该始终发布问题,因为您链接到的页面可能在以后变得不可用。以后发现这个问题的人不会理解它的重点。如果这还不够糟糕,那么首先寻求帮助,然后让帮助者查看另一个页面以了解您的问题,这不是一个好习惯。
-
好的,抱歉我的帖子。我会努力改正自己的。
标签: python