Educational goals of this lab - verify that every student can
INSTRUCTIONS:
# Prolog # Author: Mary Smith # Email: Mary.Smith@uky.edu # Section: 00 # Date: 8/31/15 ''' Purpose: to find the area and diagonal length of a rectangle, given the length and the width of the rectangle Preconditions: (inputs) User supplies the length and the width of the rectangle as numbers Postconditions: (outputs) User greeted and prompted for input of the two dimensions Rectangle area and diagonal length displayed ''' from math import sqrt # used for Pythagorean theorem def main(): # Design and implementation # 1. Output a message to identify the program print("Area and Length of Diagonal of a Rectangle") # 2. Input length and width of the rectangle from user length = float(input("Enter length of rectangle: ")) width = float(input("Enter width of rectangle: ") # 3. Calculate the area of the rectangle using product of length and width area = length + width # 4. Calculate the length of the diagonal of the rectangle using Pythagorean theorem # to find the length of the hypotenuse (the diagonal) diagonal = sqrt(length **2 + width **2) # 5. Output resulting area and length of diagonal print() print("The area of a rectangle with length", length, "and width", width) print("is", area) print("The length of the diagonal of a rectangle with length", length, "and width", width) print("is", diagonal) 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 see that you can run them.
Test Case 1:
Area and Length of Diagonal of a Rectangle Enter length of rectangle: 3 Enter width of rectangle: 4 The area of a rectangle with length 3.0 and width 4.0 is 12.0 The length of the diagonal of a rectangle with length 3.0 and width 4.0 is 5.0
Area and Length of Diagonal of a Rectangle Enter length of rectangle: 1000 Enter width of rectangle: 2000 The area of a rectangle with length 1000.0 and width 2000.0 is 2000000.0 The length of the diagonal of a rectangle with length 1000.0 and width 2000.0 is 2236.06797749979
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.
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.
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.