Hi, Zed! Again I try to learn Python by your book. I’ve just made exercise 4 Variables and Names. I have a question on which I could not find an answer. It is all about a floating point.
In the original version of the exercise, after running we have two lines with floating points “We can transport 120.0 people today.” and “We need to put about 3.0 in each car.”.
According to paragraph 1 of Study Drills, I replaced 4.0 on 4.
cars = 100
space_in_a_car = 4
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.”)
After that, we have the very lines “We can transport 120 people today.” and “We need to put about 3.0 in each car.”
The first one is without the floating point and the second is with it. Why??? All variables have numbers without a floating point except “average_passengers_per_car”!
I even typed an additional line “print(cars, space_in_a_car, cars_driven, passengers, average_passengers_per_car, carpool_capacity)” but the result is the same “100 4 30 90 3.0 120”.
I’ve looked through Python topics but I cannot find that anybody asks the same question.
I try my best but I cannot get it. Please help me understand that!