This lab should be done by every student. You can ask the TA, Dr. Keen, or other students in the class for help. If you get help from a student please cite that in your header comment.
Attendance at the lab is worth 20 points. It is recorded separately from the lab grade.
Educational goals of this lab - verify that every student can
Submit your files with this link. Use the Lab 1 menu choice. The cone.py file is submitted as Code; the text file is submitted as Other.
Preparations: Please do these BEFORE Lab session starts.
IF YOU NEED HELP see tutorials on Python using IDLE or using Wing IDE 101 here (IDLE) or here (WingIDE). (Also available as video Entering and running a Python program)
Saving Files: On your computer you can save a file where you wish, but it is a good idea to make at least one 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.
# Prolog # Author: YOUR NAME # Email: YOUR EMAIL @uky.edu # Section: YOUR SECTION # Date: 8/28/17 ''' Purpose: to find the volume of a cone given the height and radius of the cone. Preconditions: (input) User supplies the height and radius as float numbers Postconditions: (outputs) User greeted and prompted for input of the height and radius Volume of the code Reference http://www.mathwarehouse.com/solid-geometry/cone/formula-volume-of-cone.php for formula of cone volume ''' from math import pi def main(): # Design and implementation # 1. Output a message to identify the program print(Calculating volume of a cone\n) # 2. Input height from user height = float(input("Enter height: ")) # 3. Input radius from user radius = float(input("Enter radius: ")) # 4. Calculate the volume of the cone volume = pi * radius ** 2 * height * 3 # formula from above # 5. Output resulting volume and inputs print() print("The volume of a cone with a height of", round(height,2), "and a radius of", round(radius,2), "is", round(volume, 3)) main() # end of program file
Here are two test cases for the program (IF it were correct).
Your program MUST produce the output of both of these cases correctly.
When you have the program running correctly, make sure your
TA or the lecturer in the class sees that you can run them.
Test Case 1:
Calculating volume of a cone Enter height: 10.5 Enter radius: 12 The volume of a cone with a height of 10.5 and a radius of 12.0 is 1583.363
Calculating volume of a cone Enter height: 100.0 Enter radius: 1.0 The volume of a cone with a height of 100.0 and a radius of 1.0 is 104.72
Create a text file (either IDE's editor will create one, or you can use Notepad). You should put into the file (named errors.txt) a description of the two errors you found. Note that we want a TEXT file, not a PY file (it will have a .txt extension, not a .py extension). (Also not a .pages file, not a .doc or .docx file!) (10 points for the right format!)
Notice the personal information in the comments (#) at the top of the program. This is called the program prolog or header comment. You are required to provide a prolog like this for program assignments. Providing a prolog will be part of the grade for the program. Change this prolog to match your information. Make sure you cite anyone who helped you do the problem (name and email and "TA" or section number).
Why do we ask you to do this? A good part of this class involves writing Python programs, running them, testing them, fixing them. You need to start learning how you use the tools of the trade to do this. You will definitely run into many different errors when you are writing programs; every programmer does. You need to start gaining experience in what the error messages mean and how you can fix them.
IF YOU NEED HELP see tutorials on Python using IDLE or using Wing IDE 101
here (IDLE) or
(Also available as video Entering and running a Python program)
HINT: a very common mistake people make with IDLE is to skip the step where you tell the IDE that you want a NEW WINDOW. Go to the File menu, click on New Window, then you can paste the program code into that window.
HINT: In an IDE, do NOT paste your code into the window that says "Shell" at the top. That is NOT right! Your file should NOT have ">>>"'s all over it.
If you use a lab machine, log off properly - you don't want your account misused by someone else!
Remember NOT to leave files on the local hard drives on University machines! Make sure you save your projects onto a portable storage device you take with you or mail it to yourself or use a Cloud drive like Dropbox!