Processing math: 100%

CPSC120A
Fundamentals of Computer Science I

Lab 2

Type Conversion & Operators

World's Largest Ice Cream Cone

The world's largest ice cream cone was 9 feet tall, according to the Guinness Book of World Records. 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.

Details

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=πr2h3

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=43πr3

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.

Example

$ 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.

Hint

Challenge

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.

Finding Your Pace

You might think that running has very little to do with Computer Science. However, there are a lot of useful computations we can do to help a runner figure out how fast they ran. Race distances are typically given in kilometers: 5k, 10k, etc. A fast runner might run a 5K in 20 minutes, but the winning time is usually closer to 15 minutes. In the US, runners typically measure their pace in minutes per mile. We will write a program to perform these computations.

Details

In Emacs, create a Python program in a file called runner.py. Your program should have variables that store:

Your program should then compute and print the user's pace in minutes per mile. Make sure you use proper variable names, format the output nicely, and follow the courses code conventions.

Example

$ python3 runner.py
If you run a 5 kilometer race in 27 minutes and 15 seconds,
your pace will be 8.72 minutes per mile.

Hint

Challenge

Many runners set goals to improve their pace. Add to your program a variable for the user to store their desired minutes per mile into. Compute how quickly they would have to run the race, and print this value as well.

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.