《“笨办法”学python3》Ex 4

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_37797662/article/details/83858475

知识点:

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

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

程序:

#车数
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>

猜你喜欢

转载自blog.csdn.net/sinat_37797662/article/details/83858475
今日推荐