Structured of Programming Language EXERCISE 4 Janna Andrea G. Justiniano Ms . Constantino Name of Student 6/11/2024 Name of Professor 6/12/2024 Data Performed Date Submitted I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE Apply knowledge of computing appropriate to the discipline [PO: A] II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE Apply fundamental principles of Python in creating possible solutions for computing problems. [CLO: 2] III. INTENDED LEARNING OUTCOME/S OF THE LABORATORY EXERCISE At the end of this exercise, students must be able to: Solve the given problem Create documentation base on the given problem Create test cases for the problem IV. Problem definition Answer the following problems. Write a Python program that implements OOP, create a class named Rectangle to compute the Area of a rectangle. The class must pass two arguments to compute for the area of a rectangle. # Requirements Add the following lines to the codio editor. #Name: TYPE YOURNAME #School: FEU-TECH #Machine Problem number - 1 Submit your codes to canvas. Using MS Word #Name: TYPE YOURNAME #School: FEU-TECH Take 3 screenshots of the output from codio. (should inlude your username) Paste the source code to MS Document file. Download your source code from codio and upload to canvas Paste the source code to the comment section in canvas upload submission. # TEST DATA `Enter Length value:-1` `Input the width of the rectangle:-2` `The number is not a positives integer:` `Enter Length value:1.1` `Enter the width of the rectangle:2.3` `Input the correct data format is not a Positive integer:` `Enter Length value:10` `Enter the width of the rectangle:20` `The Area of the Rectangle is:200` Output: Source Code: class Shape: def __init__(self, length, width): self.length = length self.width = width def computeArea(self): if self.length < 0 or self.width < 0: print("Numbers must be positive.") else: print(self.length * self.width) try: l = int(input("Enter Length: ")) w = int(input("Enter Width: ")) result = Shape(l, w) result.computeArea() except ValueError: print("Must be integers.") 2. Write a Python program that implements OOP. Use the class name Circle. Solve for the Area and Perimeter. # Requirements Add the following lines to the codio editor. #Name: TYPE YOURNAME #School: FEU-TECH #Machine Problem number - 2 Submit your codes to canvas. Using MS Word #Name: TYPE YOURNAME #School: FEU-TECH Take 3 screenshots of the output from codio. (should inlude your username) Paste the source code to MS Document file. Download your source code from codio and upload to canvas Paste the source code to the comment section in canvas upload submission. # TEST DATA `Enter radius:-1` `You use enter positive number` `Enter radius:1.1` `You use input whole number value:` `Enter radius:10` `The answer is 314.0` `Here is the Answer: 62.800000000000004` Output: Source Code: class Circle: def __init__(self, radius): self.radius = int(radius) def computeArea(self): if self.radius <= 0: print("Numbers must be positive.") else: print("Your Area is: " + str(3.14 * pow(self.radius, 2))) def computePerimeter(self): if self.radius <= 0: pass else: print("Your Perimeter is: " + str(2 * 3.14 * self.radius)) try: r = input("Enter Radius: ") if not r.isdigit() or int(r) <= 0: raise ValueError("Must be a positive whole number.") result = Circle(int(r)) result.computeArea() result.computePerimeter() except ValueError as e: print(e) 3. Write a program that accepts integer as input and display the equivalent roman numeral and vice-versa. The program should be written in OOP. # SAMPLE GUIDE # Requirements Add the following lines to the codio editor. #Name: TYPE YOURNAME #School: FEU-TECH #Machine Problem number - 3 Submit your codes to canvas. Using MS Word #Name: TYPE YOURNAME #School: FEU-TECH Take 3 screenshots of the output from codio. (should inlude your username) Paste the source code to MS Document file. Download your source code from codio and upload to canvas Paste the source code to the comment section in canvas upload submission. # TEST DATA MENU 1. convert an integer to a roman numeral 2. convert a roman numeral to an integer 3. exit Enter your choice:1 Enter Integer - 1 Output in Roman numerals is: I Enter Integer - 3000 Output in Roman Numberals is MMM MAX VALUE IS 5000, should only accept whole number value. provide the necessary error handling. Enter your choice:2 Enter roman numeral - MMM Output in Integer is - 3000 Enter roman numberals - I Output in Integer is - 1 The conversion should accept uppercase and lowercase input. After the output, the program should return to the menu choices. Output: Source Code: class IntToRoman: def __init__(self, num): self.num = num def convert_to_roman(self): table_roman = { 1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I' } roman = '' for value in sorted(table_roman.keys(), reverse=True): while self.num >= value: roman += table_roman[value] self.num -= value return roman class RomanToInt: def __init__(self, roman): self.roman = roman def convert_to_int(self): table_int = { 'M': 1000, 'CM': 900, 'D': 500, 'CD': 400, 'C': 100, 'XC': 90, 'L': 50, 'XL': 40, 'X': 10, 'IX': 9, 'V': 5, 'IV': 4, 'I': 1 } num = 0 i=0 while i < len(self.roman): if i + 1 < len(self.roman) and table_int[self.roman[i]] < table_int[self.roman[i + 1]]: num += table_int[self.roman[i + 1]] - table_int[self.roman[i]] i += 2 else: num += table_int[self.roman[i]] i += 1 return num def process_menu(option): while option != 0: if option == 1: try: n = int(input("Enter Number (1 to 5000): ")) if n < 1 or n > 5000: raise ValueError("Number must be between 1 and 5000.") int2roman = IntToRoman(n) print("Int to Roman: " + int2roman.convert_to_roman()) except ValueError as e: print(e) elif option == 2: try: r = str(input("Enter Roman Numeral: ")).upper() roman2int = RomanToInt(r) result = roman2int.convert_to_int() if result > 5000: raise ValueError("The Roman numeral represents a number greater than 5000.") print("Roman to Int: " + str(result)) except ValueError as e: print(e) elif option == 3: print("Program Exiting..") exit(1) else: print("Invalid Input") print("\n") menu() def menu(): print("[1] Convert an Integer to a Roman Numeral") print("[2] Convert a Roman Numeral to an Integer") print("[3] Exit") try: option = int(input("Enter Option: ")) process_menu(option) except ValueError: print("Invalid input. Please enter a valid option.") menu() menu() evelopment Message V. ASSESSMENT Department Subject Code Description Term/Academic Year Computer Science CS00048 Structured of Programming Language Note: The following rubrics/metrics will be used to grade students’ output in the lab exercise 1. Program (50 pts) Program execution (20pts) Correct output (20pts) Design of output (10pts) (Excellent) Program executes correctly with no syntax or runtime errors (18 – 20) Program displays correct output with no errors (18 – 20) Program displays more than expected (10) Design of logic (20pts) Program is logically well designed (18 – 20) Standards (20pts) Program is stylistically well designed (18 – 20) Delivery (10pts) The program was delivered on time. (10) (Good) Program executes with less than 3 errors (15 – 17 ) (Fair) Program executes with more than 3 errors (12 – 14) (Poor) Program does not execute (10 – 11) Output has minor errors (15 – 17) Output has multiple errors (12 – 14 ) Output is incorrect (10 - 11) Program displays minimally expected output (8 – 9) Program has slight logic errors that do no significantly affect the results (15 – 17) Few inappropriate design choices (i.e. poor variable names, improper indentation) (15 – 17) Program does not display the required output (6-7) Program has significant logic errors (12 – 14 ) Output is poorly designed (5) Several inappropriate design choices (i.e. poor variable names, improper indentation) (12 – 14 ) The code was within 2 weeks of the due date. (6 – 7) Program is poorly written (10 - 11) The program was delivered within a week of the due date. (8 – 9) Program is incorrect (10 - 11) The code was more than 2 weeks overdue (5) V. REFERENCES Mueller(2018) Python for Data Science for dummies, Wiley Tuner (2018) Statistics For Machine Learning: Techniques For Exploring Supervised, Unsupervised, And Reinforcement Learning Models With Python And R Tuner(2018) Python Programming: 3 Books In 1: Beginner’s Guide + Intermediate Guide + Expert Guide To Learn Python Step-By-Step, Wiley Romano(2018) Learn Python Programming: The No-Nonsense, Beginner's Guide To Programming, Data Science, And Web Development With Python 3.7,Packt Publishing Morgan (2017), Data Analysis From Scratch With Python: Step-By-Step Guide , Createspace Independent Publishing Platform. Barry(2017), Head First Python: A Brain-Friendly Guide , O'reilly Media Guttag(2016), Introduction To Computation And Programming Using Python (2016), The Mit Press Courseware Materials available at www.feu.instructure.com