CS 115 Lab 1
70 Points
This lab should be done by every student. You can ask questions of the instructor
or your TA. Do not ask other students.
Due date:
- Submit the program .py with corrections and additions, by end of lab on Monday, February 1, 2021
Educational goals of this lab - verify that every student can
- Use the Python IDE to work with a program in Python (feet.py)
- Document the errors in the program and fix them
- Submit a program file to be graded using the Canvas submit link
If the file is not timestamped by the end of lab session, you get NO points!
Submit your file with the Canvas submit link.
Preparations: Please do these BEFORE Lab session starts.
- View these videos
- The difference between an interpreter and a compiler (Youtube)
- Compilers and Interpreters
- Programming errors
- Entering and running a Python program
- Where is my error?
- Make sure you have read up to section 1.7 of the Zybook.
IF YOU NEED HELP see tutorials on Python using IDLE or using Wing IDE 101
here (IDLE) or
here (WingIDE).
(Also available as a 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.
INSTRUCTIONS:
- (70 points) Problem: Documenting errrors; Getting a program to run
- On your machine, run your choice of Python IDE (IDLE or Wing or other).
- Copy and paste the Python program below into a NEW FILE in the IDE editor of your choice.
The program is everything between the two horizontal lines on the page.
-
Save the program file as feet.py.
# Prolog
# Author: YOUR NAME
# Email: YOUR EMAIL @uky.edu
# Section: YOUR SECTION
'''
Purpose:
convert feet to inches, using fact that there are 12 inches in 1 foot
Pre-conditions (input):
number of feet (floating point)
Post-conditions (output):
number of inches, floating point with 2 decimals rounded
'''
def main():
# Design and implementation
# 1. Output a message to identify the program, and a blank line
print("Conversion of feet to inches")
print()
# 2. Input amount of feet from user
feet = float(input("How many feet? ")
# 3. Calculate number of inches
# 12 inches in one foot
inches = feet + 12
# 4. Output resulting inches and given number of feet
print()
print(feet, "feet is {:.2f} inches".format(inches))
main()
# end of program file
#
- (10 points) Update the prolog
Notice the personal information in the comments (#) at the top of
the program. This is called the program prolog.
You are required to provide a prolog like this for program assignments.
Change this prolog to match your information.
- (25 points) Find the syntax error and document it and fix it
- Try executing it with the Run button. It crashes!
You have to fix the syntax error before you can run the program.
You don't need to add any statements to the ones already in the program to fix the error.
Fix the error in the simplest way.
- To document the error and how you fixed it,
put a multi-line comment at the bottom of the program file, after the "main()" call.
That means the comment starts and ends with three single quotes.
- Answer these questions in this comment. Please number each answer.
- 1. State what the syntax error was, for example, "it was missing a semicolon".
- 2. Copy and paste into the comment the error message you got for the error.
The error message is in the Shell window. The last line of the error message is the most important; make sure you get that one. The other info starting at "Traceback" can be useful. Copy those also.
- 3. Describe how you fixed the syntax error.
- Hint for IDLE:
IDLE's editor does tell you what line number the cursor is in,
just look in the lower right corner of the edit window.
You may get a box that says "Syntax Error" and an OK button. This is normal
for IDLE. Look for a highlighted word in the edit window; that's where IDLE thinks
the error is.
- (25 points) Find the semantics error and document it and fix it
- Run the program now that the syntax error is fixed. You can use any numbers you like
as long as you know what the right answer is. You can use the numbers in the test cases
if you like. Does the program give the right answer? No. Find out why.
- Answer these questions in the same multi-line comment at the bottom of the file.
Please number the answers.
- 4. What is the semantics (logic) error? NOT just that "the answer is wrong". Why is the answer wrong? Be specific.
- 5. State what line the semantics error was on in the program.
- 6. State how you fixed the semantics (logic) error.
- (10 points) Demonstrating the Test Cases
-
After you fix the two bugs, it should run without errors and produce the
correct output given in the test cases.
- Here are three test cases for the program (after it is corrected).
Your program, after you fix it, MUST produce the output of these cases correctly.
NOTE: we will use these test cases to test your program when grading.
When you have the program running correctly, make sure your
TA or Dr. Keen sees that you can run at least one of them.
The italicized bold text is what the user types in while the program is running.
Test Case 1: (user inputs are in italic and bold)
Conversion of feet to inches
How many feet? 17.2
17.2 feet is 206.40 inches
Test Case 2: (user inputs are in italic and bold)
Conversion of feet to inches
How many feet? 10
10.0 feet is 120.00 inches
Test Case 3: (user inputs are in italic and bold)
Conversion of feet to inches
How many feet? 0
0.0 feet is 0.00 inches
-
Submit the program (feet.py) as a submission for Lab 1 with the Canvas link.
This must be done by end of your lab period.
If you have submitted and still had errors, fix them and submit again.
You can submit as many times as you want.
We grade the last one we receive.
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
here (Wing).
(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 any 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!