Purpose: To practice using loops to repeat actions until a condition is met (and solve a practical problem at the same time!) Degree of Difficulty Easy A friend of yours has gotten the new \"Rocket\" credit card. Every dollar purchased gets you 1000 meters towards a free one-way trip to the planet Venus! To attract customers the card offers a novel interest rate For each month in debt, the percentage owed in interest increases by a power of 2. For example, after 1 month, the interest owed is equal to 2% (21) of the original debt. After 2 months, the interest is 4% (22) of the original debt and so on. In general: interest (m) d x (2\" /100) Note: This formula is not a Python assignment statement! It is an equation that says that if you know the quantities m (the number of months) and d (the original debt), you can calculateavalue using the right side of the equation, giving you a quantity that tells you the the total interest after m months Write a program which does the following Prompt the user toenter an initial amount of Rocket credit card debt. You must make sure that the user enters a positive number. If they do not enter a positive number, print a message informing them so and prompt them to enter the initial amount of debt again. Keep doing this until they enter a positive number Starting from month 1, print to the console the total payment owed at 1-month intervals. Thus, for month 1, month 2, etc., you should print out the total payment owing, which consists of the interest plus the original debt. Your program should stop after the first month where the total payment owing is greater than 100 times the original debt (that\'s the point at which the credit company calls in its debts, whether you like it or not!) Don\'t forget to import the math module if you need math functions Hint: A correct solution should make use of two separate while-loops. Sample Run Sample input and output (input typed by the user is shown in green text) Enter amount of debt in dollars Error Debt must be number a positive Enter amount of debt in dollars you owe $1.02 After 1 months $1.04 After 2 months you O We you owe: $1.08 After 33 months $1.16 After 4 months you ow you owe $1.32 After 5 months owe 1.6400000000000001 After 6 months you $2.2800 000000000002 After 7 months you owe you owe $3.56 After 8 months $6.12 After 9 months you owe you owe $11.24 After 10 months $21.48 After 11 months you owe you owe $41.96 After 12 months $82.92 After 13 months you owe After 14 months $164.84 you owe Time to pay up
Python 3 Code:
while(True):
print(\"Enter the amount of debt in dollars!\")
debt = int(input())
if(debt <= 0):
print(\"Error! Debt must be a positive number!\")
else:
m = 1
total_payable = debt
while(True):
total_payable = debt + float(2.0**m)/float(100.0)
print(\"After\", m, \"months, you owe $\", total_payable )
if(total_payable >= debt*(100)):
print(\"Time to pay up!\")
break
m = m +1
break
Sample Output:
Enter the amount of debt in dollars!
-7
Error! Debt must be a positive number!
Enter the amount of debt in dollars!
1
After 1 months, you owe $ 1.02
After 2 months, you owe $ 1.04
After 3 months, you owe $ 1.08
After 4 months, you owe $ 1.16
After 5 months, you owe $ 1.32
After 6 months, you owe $ 1.6400000000000001
After 7 months, you owe $ 2.2800000000000002
After 8 months, you owe $ 3.56
After 9 months, you owe $ 6.12
After 10 months, you owe $ 11.24
After 11 months, you owe $ 21.48
After 12 months, you owe $ 41.96
After 13 months, you owe $ 82.92
After 14 months, you owe $ 164.84
Time to pay up!