# number of cars cars = 100 # number of drivers + passengers per car space_in_a_car = 4.0 # number of drivers drivers = 30 # number of passengers passengers = 90 # computes cars without drivers cars_not_driven = cars - drivers # A useless variable, but could be modified to be "optimized nubmer of drivers" cars_driven = drivers # calculates the number of free spaces, but the space per car should probably # include the drivers, so either the space_in_a_car should be decreased, or # the average passengers per car should be recalculated, as a driver is not a passenger! carpool_capacity = cars_driven * space_in_a_car #I'm changing this from passengers / cars_driven to (passengers+drivers)/cars driven average_passengers_per_car = (passengers+drivers) / cars_driven #note that we can do math, but that printing is the only way to display what is #being done 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." #I modified below to show that drivers are also part of the carpool print "We have", passengers+drivers, "to carpool today." print "We need to put about", average_passengers_per_car, "in each car."
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question