联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-05-24 08:31

CS10 Python Programming Homework 5

40 points

Dictionaries, Files, OOP

1. You must turn in your program listing and output for each program set. Start a new sheet or sheets of paper

for each program set. Each program set must have your student name, student ID, and program set

number/description. All the program sets must be printed and submitted together with your Final Exam.

Once you complete your Final Exam and leave the classroom you will not be able to submit Homework 5.

Late homework will not be accepted for whatever reasons you may have.

********************************************************************************************************************************

for this homework, you are also to submit All Program Sets to Canvas under Homework 5 link

********************************************************************************************************************************

a. Name your files : PS1_firstinitial_lastname.py for Program Set 1 and so on. PS means program

set.

b. You still have to submit the paper copies together with the rest of the Homework 5.

c. You have till 11:59pm on the day of Final Exam to submit all Program Sets to Canvas. If the

deadline is past, Program Sets will not be graded even if you submit the paper copy on time.

d. You must submit both hardcopy and upload the Program Sets to Canvas to be graded. If you

only submit the hardcopy or only upload to Canvas you will receive a zero for the Program Sets.

You must submit all the hardcopies of all Program Sets of Homework 5.

e. if you do not follow instructions on file naming provided in this section you will receive a zero for

the whole of Homework 4.

2. You must STAPLE (not stapled assignments will not be graded resulting in a zero score) your programming

assignment and collate them accordingly. Example Program set 1 listing and then output, followed by

Program Set 2 listing and output and so on.

3. 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).

4. 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

- 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

- 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

- 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 3 points

- to be displayed at the end of the program listing(codes)

- must use test cases when provided

Program 1- Tea Leaves Sales Report (15 Points)

1. Here is the sample of the text file (datafile) for the tea sales (tea.txt). You have to create this file yourself.

Green Tea:8580.0:7201.25:8900.0

Earl Grey:10225.25:9025.0:9505.0

Ceylon:6700.1:5012.45:6011.0

Jasmine:9285.15:8276.1:8705.0

Mint Tea:7901.25:4267.0:7056.5

The data reads as follows – tea_name:store1_Sales:store2_Sales:store3_Sales

2. The output displayed as follows:

>>>

Ceylon 6700.10 5012.45 6011.00 17723.55

Earl Grey 10225.25 9025.00 9505.00 28755.25

Green Tea 8580.00 7201.25 8900.00 24681.25

Jasmine 9285.15 8276.10 8705.00 26266.25

Mint Tea 7901.25 4267.00 7056.50 19224.75

42691.75 33781.80 40177.50

>>>

The last row is the store totals for all the kinds of tea leaves sold. The last column is the total sale for

each kind of tea leaves sales. Note that the tea names are sorted.

3. Write a program to read in the tea.txt textfile and then print the report as shown in #2 above.

4. You must use dictionary. You can also use list, tuples, sets if necessary.

Program 2 – OOP (10 points)

Write a program to calculate and display the loan for buying a car.

1. Create a class call Loan.

Data fields in the Loan class include:

1 Annual Interest Rate (Float)

2. Number of years of loan (Float)

3. Loan Amount (Float)

4. Borrower’s Name (string)

2. Create the initializer or constructor for the class with the above data fields. Make the data fields private.

3. Create accessors (getter) for all the data fields.

4. Create mutators (setters) for all the data fields.

5. Create a class method - getMonthlyPayment where

monthlyPayment = loanAmount * monthlyInterestRate / (1 ‐ (1 / (1 + monthlyInterestRate) ** (numberOfYears * 12)))

note: that the monthly interest rate = annualinterest / 1200

5. Create a class method - getTotalPayment where

totalPayment = getMonthlyPayment() * numberOfYears * 12

7. Write a test program (main function) to allow the user to enter the following:

1. Annual Interest Rate

2. Number of Years of Loan

3. Loan Amount

4. Borrower’s Name

Allow the user to change the loan amount and reprint the new loan information.

The output should look like this:

>>>

Enter yearly interest rate, for example, 7.25: 2.5

Enter number of years as an integer: 5

Enter loan amount, for example, 120000.95: 1000.00

Enter a borrower's name: John Jones

The loan is for John Jones

The monthly payment is 17.75

The total payment is 1064.84

Do you want to change the loan amount? Y for yes or enter to quit y

Enter new loan amount 5000

The loan is for John Jones

The monthly payment is 88.74

The total payment is 5324.21

>>>

Program Set 3 (15 points)

Use Program set 2 codes and use tkinter module to create a GUI program for the Loan program that looks like

the below image.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp