193k views
3 votes
Good news!! You won the grant price just for being awesome!! However, as in many things in life, there is a catch. Your prize will be paid to you in monthly installments.

The payments will start in the amount of 1 dollar. Obviously that is not too much of a price at the beginning. But here are two rules we can apply every month to increase the installments.

Rule A - Double the installment amount.
Rule B - Triple the installment amount.

You are free to apply Rule A every month, but Rule B can be applied only every other month.

To maximize payments.

1st month's payment 1 dollar.
2nd month's payment 2 dollars. (doubled the amount)
3rd month's payment 6 dollars. (triple it every other months)
4th month's payment 12 dollars. (double the amount)
5th month's payment 36 dollars. (triple it every other month)
6th month's payment 72 dollars. (double the amount)
7th month's payment 216 dollars. (triple it every other month)

and so on ...

Write a program that will compute the monthly payment amounts you will get over a given number of months.

Your program should take the number of months from user and create a loop to compute the payments for each month and output on screen.

User Mash
by
4.9k points

1 Answer

3 votes

Answer:

We will write 2 functions to calculate the number of doubles and triples that have occurred by a certain month and then call these functions at each step of our loop to calculate and output the payment for that month.

Step-by-step explanation:

def numberofdoubles(months):

return months DIV 2;

def numberoftriples(months):

return (months - 1) DIV 2;

n = input("How many months would you like to calculate payment for?");

for i in range(1 to n):

doublefactor = 2^(numberofdoubles(i))

triplefactor = 3^(numberoftriples(i))

payment = 1*doublefactor*triplefactor

print("Month " + i + ": R" + payment)

User Guenther Schmitz
by
4.7k points