Question
Assignment Overview This lab focuses on defining and using functions. The Problem You will write a program that asks the user if they want a
Assignment Overview
This lab focuses on defining and using functions.
The Problem
You will write a program that asks the user if they want a calculation for the surface area or volume of a cone. The valid choices are 'y/n' or 'Y/N.' Any other value is a "Bad Choice." Your program will loop until it gets a valid choice. No more than 2 bad choices allowed. If the choice is y, then the program prompts the user for the type of calculation. A 'v/V' indicates volume and an 's/S' indicates surface area. The program then prompts the user for the radius and height of a 3-dimensional cone and then calculates and prints either the surface area or the volume of the cone. The calculation of the surface area and the volume will be done in functions, as will the gathering of the inputs. The program will then loop back and ask the user if they want a calculation. If the choice is 'n/N,' then print "Goodbye" and end the program.
Your program for this part will function as follows:
- Print out a message indicating what the program does (Print only once).
- Prompt the user for the radius (a non-negative float) in feet.
- Prompt the user for the height (a non-negative float) in feet.
- Print the radius and height but rounded to 2 decimal digits.
- Print the surface area and volume, rounded to 2 decimal digits.
- Add a counter that ends the program if a user enters more than 2 bad choices.
This version of the program will check that the input for the radius, height, and calc type is correct; if the user types anything other than a non-negative float, it can crash. To prevent this we will use the try/except method to trap the exception and the abs() function. Hint: use the ValueError exception label. Program should NOT crash for any bad input. This means for any requested item.
Your program must define and invoke three functions:
- cone_surface_area(r,h): returns the surface area of a cone of radius r and height h
- cone_volume(r,h) : returns the volume of a cone of radius r and height h.
- get_input(): returns calc type (v/s), radius, and height.
The formulas for finding these values are as follows:
Import the math module and use math.pi and math.sqrt() in these calculations.
Main program should only call functions, not do calculations in main.
Define functions at top of code.
Use a control variable to control loop.
You can use the round () function or the formatting techniques of chapter 4.
The round function has the form round(value, 2) where the argument 2 is the desired decimal places. The value argument can be an expression or a variable.
Use the logic from the previous lab for the looping structures and answer filter.
Always reuse code if possible - why reinvent the wheel?
input this module in to the code:
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
python import math def conesurfacearear h Calculates the surface area of a cone Parameters r float R...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started