As usual, create a directory to hold today's files. All programs that you write today should be stored in this directory.
$ cd ~/cs120/labs $ mkdir lab3 $ cd lab3
In Emacs, create a Python program in a file called oil_drum.py. The program should print the number of gallons in an oil drum. An oil drum is 33.5 inches tall with a radius of 11.25 inches. The volume of a cylinder can be computed using the equation:
v = a × h
a = π × r2
Where is the volume of a cylinder, is the area of the base of the cylinder, the height of thy cylinder, and is the radius of the cylinder. One gallon is 231 cubic inches. The program should use meaningful names for values and simple statements to make the program more readable. The output should be nicely formatted and labeled.
A single sheet of paper is 0.004 inches thick. If you fold the paper in half, the two halves of the sheet of paper are together 0.008 inches thick. If you fold the paper in half again the four quarters are together 0.016 inches thick. How thick would the paper be if you folded it in half 10 times?
In Emacs, create a Python program in a file called origami.py. The program should print how thick a piece of paper would be if you folded it in half 10 times. The program should use meaningful names for values and simple statements to make the program more readable. The output should be nicely formatted and labeled.
$ python3 origami.py A piece of paper folded in half 10 times would be 4.096 inches thick.
How many times do you have to fold a piece of paper in half for its height to reach the moon? Use your program to figure it out. The moon is about 238857 miles from the Earth. The actual distance varies because the moon's orbit is not circular. Change the variable for the number of folds until you find the smallest number of foldes that is greater than the distance to the Moon. Note, you will need to convert the thickness to miles or the distance to the moon to inches to make the comparison correctly.
The world's largest ice cream cone was 9 feet tall, according to the
While impressive based on the height alone, one has to wonder how much ice cream actually went into making such a monstrosity. Math is of course our friend, but writing a program could make it easier to figure out how big of an ice cream cone you and your friends would have to make in order to beat the current record.In Emacs, create a Python program in a file called ice_cream.py. The program should print the volume in, in cubic feet, of the worlds largest ice cream cone. The cone is 9 feet tall with a radius of 2 feet. Assume that the entire cone is filled with ice cream and that there is a perfect half-sphere of ice cream on top of the cone, like this:
The volume of a cone can be computed using the equation:
$$v = \pi \cdot r^{2} \cdot \frac{h}{3}$$
Where \(v\) is the volume of a cone, \(r\) is the radius of the cone, and \(h\) is the height of the cone. The volume of a sphere can be computed using the equation:
$$v = \frac{4}{3} \cdot \pi \cdot r^{3}$$
Where \(v\) is the volume of a sphere and \(r\) is the radius of the sphere. The program should use meaningful names for values and simple statements to make the program more readable. The output should be nicely formatted and labeled.
$ python3 ice_cream.py The volume of the cone is 37.69911184307752 cubic feet. The volume of the sphere is 33.510321638291124 cubic feet. The volume of ice cream is 54.454272662223076 cubic feet.
cone_height
and cone_radius
are the inputs to the program.
Set the height
variable to 9 and
the radius
variable to 2. cone_volume
, sphere_volume
,
and ice_cream_volume
. Set each of these
variables equal to arithmetic expressions that compute the
correct value. Note that the ice_cream_volume
variable depends on the other two variables, so it must be
defined after them.So how many children can the world's largest ice cream cone feed? Modify your program to calculate and print the result. Assume that a single serving of ice cream is 4 oz and note that there are 957.506 oz in a cubic foot.