CS10 Python Programming Homework 5
40 points
Dictionaries, Files, OOP
- You must submit to Canvas only your program listing and output for each program set. Each program set must have your student name, student ID, and program set number/description. Late homework will not be accepted for whatever reasons you may have.
**
for this homework, you are only to submit All Program Sets to Canvas under Homework 5 link
a. Name your files : HW5_PS1_lastname_firstinitial.py for Program Set 1 and so on. PS means program set.
b. You have till 11:59pm as shown on Canvas to submit all Program Sets to Canvas. If the deadline is past, Program Sets will not be graded.
c. if you do not follow instructions on file naming provided in this section you will receive a zero for the whole of Homework 5.
- Please format you output properly, for example all dollar amounts should be printed with 2 decimal places.
Make sure that your output values are correct (check the calculations). - Each student is expected to do their own work. IF IDENTICAL PROGRAMS ARE SUBMITTED, EACH IDENTICAL PROGRAM WILL RECEIVE A SCORE OF ZERO.
Grading:
Each program set must run correctly syntactically, logically, and display the correct output as specified. If the program set does not run correctly, a zero will be given. For each Program set, if the program executes properly with proper syntax, logic, and displays the correct output, then points will be deducted for not having proper: a. Comments (1 pt deducted for each occurrence)
- Your name, description at the beginning of each program set. Short description of the what each section of your codes do.
b. Consistency/Readability (2 pts deducted for each occurrence) - Spacing(separate each section of codes with a blank line
- Indentation
- Style (proper naming of variables no a,b,c – use descriptive and mnemonics)
-each function must include type hints or annotations except for the main()
-include docstrings for every function
c. Required elements (2 pts deducted for each occurrence) - Use tools that have been covered in class
- proper formatting for output when specified
- all monetary values must be in 2 decimal places
d. Output - if no output is provided for either the hardcopies or uploaded file, a zero will be given for that program set.
- Output must to be displayed at the end of the program listing(codes), if it not displayed at the end of the program listing it is equivalent to no output.
- must use test cases when provided in the Program set question. Provide your own test cases if the program set does not ask for any. The minimum test cases you provide on your own is 5 or more. If you provide less then 5 test cases per Program Set then that program set will receive a zero grade.
Program 1- Tea Leaves Sales Report (15 Points)
- Here is the sample of the text file (datafile) for the tea sales (tea.txt). The tea.txt file is provided for you on Canvas.
1 | Green Tea:8580.0:7201.25:8900. |
1 | The data reads as follows – tea_name:store1_Sales:store2_Sales:store3_Sales |
1 | The output displayed as follows(no commas required for the numbers in this output) |
>>>
1 | Ceylon 6700.10 5012.45 6011.00 17723. |
>>>
1 | The last row is the store totals for all the kinds of tea leaves sold. The last column is the total sale for |
1 | a. Write a program to read in the tea.txt textfile and then print the report as shown in #2 above. |
Program Set 2(15 points)
- The textabbrv.txt file is provided for you on Canvas. You are to use this text file and write and program as shown in the output sample. Allow the user to run the program as many times as the user wants. You must provide at least 5 test cases.
1 | a. You are to write a program where the user enters an abbreviation and your program will translate it to |
1 | b. your program should take into consideration all punctuation marks that the user enters and displayed it |
1 | c. You must use dictionary. You may use list, tuples, sets if you need to. |
1 | Below is the textabbv.txt file contents(use the textabbv.txt file provided for your program): |
1 | The output should display: |
>>>
1 | Enter a message to be translated: (prompt for the user) |
Program 3 – OOP (10 points)
Write a program to calculate and display the loan for buying a car.
- Create a class call Loan.
Data fields in the Loan class include:
1 Annual Interest Rate (Float) - Number of years of loan (Float)
- Loan Amount (Float)
- Borrower’s Name (string)
- Create the initializer or constructor for the class with the above data fields. Make the data fields private.
- Create accessors (getter) for all the data fields.
- Create mutators (setters) for all the data fields.
- Create a class method - getMonthlyPayment where
1 | monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / (1 + monthlyInterestRate) ** (numberOfYears * 12))) |
1 | note: that the monthly interest rate = annualinterest / 1200 |
- Create a class method - getTotalPayment where
totalPayment = getMonthlyPayment() numberOfYears 12
- Write a test program (main function) to allow the user to enter the following:
- Annual Interest Rate
- Number of Years of Loan
- Loan Amount
- Borrower’s Name
Allow the user to change the loan amount and reprint the new loan information.
The output should look like this: