Due Date: This lab will be performed in lab sessions on Monday, January 25, 2021.
This lab should be done by every student. You can ask the instructor or your TA or other students in the class for help.
Educational goals of this lab - verify that every student can
IF YOU NEED HELP
Saving Files: On your computer you can save a file where you wish, but it is a good idea to make a folder for your CS 115 work, to make it easy to find. Or you can save a file on a memory stick or a Cloud storage account (like Dropbox) or email it to yourself.
INSTRUCTIONS:
# Prolog # Author: YOUR NAME # Email: YOUR EMAIL @uky.edu # Section: YOUR SECTION # Date: 1/25/21 ''' Purpose: to find the circumference and area of a circle given the diameter. Preconditions: (input) User supplies the diameter as float number Postconditions: (outputs) User greeted and prompted for input of the diameter Circumference and area of the circle is reported Reference https://www.mathsisfun.com/geometry/circle.html for formula of circumference and area ''' from math import pi # the famous 3.14159... to 15 places! def main(): # Design and implementation # 1. Output a message to identify the program print("Calculating circumference and area of a circle\n") # 2. Input diameter from user diameter = float(input("Enter diameter (m): ")) # 3. Calculate radius from diameter, half the diameter radius = diameter / 2 # 4. Calculate area in square meters area = pi * radius ** 2 # ** means raise to a power # 5. Calculate the circumference of the circle (in meters) circum = pi * diameter # 6. Output resulting circumference, area, and inputs print() print("The radius of a circle with a diameter of {:.3f} m".format(diameter)) print("is {:.3f} m".format(radius)) print() print("The circumference of the circle is {:.3f} m".format(circum), "and the area is {:.3f} square m".format(area)) main() # end of program file
Here are some test cases for the program. You should run your program
with the numbers given below and make sure it comes out with the answers
displayed in the test cases.
If not, go back and check your program for mistakes.
The bold, italicized text is what the user types in while the program is running.
Test Case 1:
Calculating circumference and area of a circle Enter diameter (m): 1 The radius of a circle with a diameter of 1.000 m is 0.500 m The circumference of the circle is 3.142 m and the area is 0.785 square m
Calculating circumference and area of a circle Enter diameter (m): 100 The radius of a circle with a diameter of 100.000 m is 50.000 m The circumference of the circle is 314.159 m and the area is 7853.982 square m
Calculating circumference and area of a circle Enter diameter (m): 5.0 The radius of a circle with a diameter of 5.000 m is 2.500 m The circumference of the circle is 15.708 m and the area is 19.635 square m
You don't have to save this program file unless you want to. There is no file submission for this assignment. Make sure your demonstration is witnessed during the lab! That is how you get 10 points.