《“笨辦法”學python3》Ex 4
阿新 • • 發佈:2018-11-08
知識點:
變數賦值,直接:名+=+值
==用於檢查兩邊是否相等,要與=區分.
程式:
#車數 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>