笨办法学python3_ex.4

第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_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.")

运行结果如下:


运行结果

你可能感兴趣的:(笨办法学python3_ex.4)