Lab 2 (2)

docx

School

Georgia State University *

*We aren’t endorsed by this school

Course

1101

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

4

Uploaded by simone8420

Report
CS 1301 Lab 2 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 ??? 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 If the file is not timestamped by the end of lab session, you get NO points! Submit your file to the I-college Dropbox. 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 1301 work, to make it easy to find. INSTRUCTIONS: (70 points) Problem: Documenting errors; Getting a program to run o On your machine, run your choice of Python IDE (IDLE or Wing or other). o 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. o Save the program file as feet.py. # Prolog # Author: YOUR NAME
# Email: YOUR EMAIL @gsu.edu # Section: YOUR SECTION ''' Purpose: convert inches to feet, using fact that there are 12 inches in 1 foot Pre-conditions (input): number of inches (floating point) Post-conditions (output): number of feet, 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 inches to feet") print() # 2. Input amount of inches from user int inches = float(input("How many inches? ") # 3. Calculate number of feet # 12 inches in one foot feet = inches * 12 ; # 4. Output resulting feet and given number of inches print() print(inches, "inches is {:.2f} feet".format(feet)) main(): # end of program file # o (20 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. o (30 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. o (30 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 if 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. o (20 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.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
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 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 inches? 206.40 206.40 inches is 17.2 feet Test Case 2: (user inputs are in italic and bold) Conversion of feet to inches How many inches? 120 120.00 inches is 10.0 feet Test Case 3: (user inputs are in italic and bold) Conversion of feet to inches How many inches? 0 0.00 inches is 0.0 feet o Submit the program (feet.py) as a submission in I-college drop box. This must be done by DUE 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.