""" Program: CS 115 Lab 8c Author: Your name Description: This program computes geometric quantities. """ import sys import math def get_numeric_val(): """ Ask the user for a number Exit if the user does not supply a positive value. Otherwise, return the value they entered """ num = float(input('Enter a positive numeric value: ')) if num <= 0: sys.exit('Error: that number was not positive.') return num def get_menu_choice(): """ Print the menu and return the user's selection """ pass def compute_square_area(side): """ Compute and return the area of a square. Parameter: side length of the square """ pass def compute_circle_area(radius): """ Compute and return the area of a circle. Parameter: radius of the circle """ pass def compute_cube_volume(edge): """ Compute and return the volume of a cube. Parameter: edge length of the cube """ pass def main(): menu_choice = get_menu_choice() # Get the user's first choice while menu_choice != 'q': user_num = get_numeric_val() # Get the side length (etc.) if menu_choice == 'a': print('The area of a square with side length ', user_num, ' is ', round(compute_square_area(user_num), 5), '.', sep="") elif menu_choice == 'b': print('The area of a circle with radius length ', user_num, ' is ', round(compute_circle_area(user_num), 5), '.', sep="") elif menu_choice == 'c': print('The volume of a cube with edge length ', user_num, ' is ', round(compute_cube_volume(user_num), 5), '.', sep="") menu_choice = get_menu_choice() # Get user's next choice main()
Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit?
Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit? A Enter a numeric value: 5 The area of a square with side length 5.0 is 25.0. Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit? q
Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit? c Enter a numeric value: 2 The volume of a cube with edge length 2.0 is 8.0. Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit? d Enter a positive numeric value: 5 The volume of a sphere with radius length 5.0 is 523.59878. Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit? e Enter a positive numeric value: 12.2 The area of an equilateral triangle with side length 12.2 is 64.44961. Would you like to a. Calculate the area of a square? b. Calculate the area of a circle? c. Calculate the volume of a cube? d. Calculate the volume of a sphere? e. Calculate the area of an equilateral triangle? q. Quit? q