Credit card interest Write a Python program that determines

Credit card interest. Write a Python program that determines the number of months required to payoff a credit card balance—assuming no other purchases are incurred on the card. You will need to import the math module for this program. In particular, you will find the math.log() function to be useful. (See the pictures for more instructions)

Consider the following variables.
• b = credit card balance
• n = number of months to payoff balance

• p = monthly payment (in dollars)

• r = effective (monthly) interest rate

As an example, suppose you have a credit card with an 18% annual percentage rate (APR). With the card, you made a purchase costing $350. As a result, b = 350, r = 0.18/12, and assume p = 10. Substituting these numbers into the above equation gives n = 50. That is, assuming a monthly payment of $10, it will take over 4 years to pay off a purchase of $350.

In your Python program, the user provides the following input: credit card balance (b) and annual percentage rate. Your output will show for each monthly payment (p) between 1% and 25% of the balance b, the number of months required to payoff the credit card

NOTE: When computing logarithms, the result is undefined for 0 and negative num- bers. For example, log(0) and log (-1.9) are undefined. Therefore, you will need to check for this condition in your program.

br log(1 log (1 r)

Solution

import math; # importing required modules

import sys;

b=eval(input(\"Credit card balance ($): \")); # getting i/p from user

p=eval(input(\"Anuual Percentage Rate (%): \"));

if(b<1 and p<1): # exit if values are not correct

print(\"Values should be greater than 0\");

sys.exit();

print(\"---------------------------------\");

print(\"% Months to payoff balance\");

print(\"---------------------------------\");

for r in range(25):# every r from 1 to 25

s=(1-(b*r)/p); # formula

if (s<1):

print(\"Please enter another value, since log for negative numbers cannot be defined\");

sys.exit();

t=1+r;

print(t);

p=-(math.log(s,10)) # given formula

q=math.log(t,10);

if (p==0 and q==0):

continue;

print(r,\" \",p/q);

Credit card interest. Write a Python program that determines the number of months required to payoff a credit card balance—assuming no other purchases are incur
Credit card interest. Write a Python program that determines the number of months required to payoff a credit card balance—assuming no other purchases are incur

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site