attaching the document
finalExam 1 Submission Requirements: • One Word document (the file name must be FinalExam.docx) containing the testing and outputs (i.e., screenshots) of the execution of your Python programs as the solutions for the following questions (items in this Word document must be in the same order as the questions). o To test your program and take screenshots, you must use the same inputs as shown in the sample screenshots (if there are any) for your testing and submissions. ▪ You submitted test screenshots should have one more testing case in addition to the ones from your testing like the sample outputs given. • Your Python programs (that is, the .py program files)—note that there are specific requirements on the program names. Note: o Your code must be properly commented (like the examples in Code Archive; you don’t have to comment on every line of code.) o On the top of your program, there must be 3~5 lines of the comments of your full name and date/time when you have completed the programs. o There should be other comments for functions/methods, classes. • (Attach your program files individually; do not zip the programs; do not put the Python code in the Word document.) Q1 (50 points) Write a Python program “FinalExam1.py” to complete the following: • Define a class Shape (to be used as a super class) with data attributes color, filled (you may define “filled” in whatever you prefer, such as 1—filled, 0—not filled; yes—filled, no—not filled, or using True/False, …). • Define a subclass, Triangle, that extends class Shape, with 3 data attributes: side1, sisde2, side3 (for the 3 sides). • Implement methods __init__ and __str__ in both of the classes • Implement methods, area() and perimeter() for class Triangle. • Implement regular set/get methods for the data attributes. • Define regular main() function in which proper inputs should be read from keyboard (you need to use try-except for validation of the inputs—see the following sample testing) for the creation of Triangle object and display the object properties, such as the color, whether filled or not, area, perimeter. o Need to check whether the input can form a triangle (if the sum of any two sides is less than the third side, all these 3 inputs for the sides cannot form a triangle.) • Test your program and take screenshots of running your program. • Use the following sample tests for your reference. 2 (Note. You may use the following formular to calculate the area of a triangle given 3 sides) 3 Q2 (50 points) Write a Python program (its name must be “FinalExam2.py”) that reads a string and check the string to see whether it is a valid “secure code” according to the following rules: • At least one uppercase letter. • At least one lowercase letter. • It includes at least two digits and the sum of the digits must be an odd number • It includes at least one vowel (Vowels are the letters a, e, i, o, u and their uppercase cousins). • It includes at least one special character (i.e., @, #, $, %, &). Specifically, the program (FinalExam2.py) must meet the following detailed requirements: 1. Define a function, count_vowels(str), which return the number of vowels included in the string str. 2. Define a function, count_special_character(str), which return the number of special characters (defined above) included in the string str. 3. Define a function, count_uppercase(str), which return the number of uppercase letters included in the string str. 4. Define a function, count_lowercase(str), which return the number of lowercase letters included in the string str. 5. Define a function, digit_property(str), which return a list of two items: the first one being the number of digits included in str, the second being the sum of these digits in str. (Hint, you may find “if c.isdigit()….sum += int(c)”, the functions int() and isdigit() very useful.) 6. Define a function, is_valid_secure_code(str), which return True if str is a valid secure code as defined above, False if not. a. Hints: you would call the functions defined above in this function and print out information/properties regarding str—see the following outputs of sample executions for your reference. 7. The program reads only one string and prints relative information about this string—see the following outputs of sample executions for your reference (note: the above defined functions must be used/called in the program in some way). Hints: Python string has defined many functions/methods for you to use in this project; also you may find the following function, if called, will return a list of Characters (or single-letter-strings), for example, [“h”, “e”, “l”, “l”, “o”] for “hello” useful for this project: 4