Homework 3
The deadline is Sunday, the 26th of September, 23:59 (Estonian time).
Exercise 1. Number of days in months
Rewrite the number of days in months program using a function called number_of_days that takes the number of a month as its parameter and returns the number of days in that month.
Example of the function call:
>>>number_of_days(3) 31 >>>number_of_days(9) 30
Test the program on various input values.
Exercise 2. Price difference
Write a function called price_difference that calculates the difference between the price on the installment plan and the initial price of the product. The function should take three parameters:
- the initial price of the product
- monthly payment
- number of months on the installment plan.
Example of the function call:
>>>price_difference(200,10,30) 100 >>>price_difference(200,20,12) 40
Modify the program so that it asks the user for the initial price of the product and two different installment plans. The program has to compare the plans and output the plan which is the best for the user.
Example of the program output:
What is the price of the product? 200 What is the monthly payment on the first installment plan? 10 How many months does the first installment plan last? 30 What is the monthly payment on the second installment plan? 20 How many months does the second installment plan last? 12 The second installment plan is better!
Hint
Save the price difference (returned by the function) in a variable. To call the function twice, you will need two different variables. You can then compare these two values and use if-else to choose the best installment plan.
Go to Moodle and upload your solution into Homework 3.