Question: ##Interest calculator 10-3 from decimal import Decimal from decimal import ROUND_HALF_UP import locale as lc #locale.setlocale(locale.LC_ALLl, us) ## throws error, not needed? print(Interest Calculator) print()

##Interest calculator 10-3
from decimal import Decimal
from decimal import ROUND_HALF_UP
import locale as lc
#locale.setlocale(locale.LC_ALLl, "us") ## throws error, not needed?
print("Interest Calculator")
print()
#figure interest rate
def get_number(loan, interest_rate):
interest = loan * (interest_rate / 100)
return interest
#main
def main():
choice = "y"
while choice.lower() == "y":
line = "{:20} {:>12}" ##why this? -- formatting, and provides print cmd
loan = input("Enter loan amount: ").strip('$').replace(',' ,'')
#replace K, need to set up k as well
if "K" in loan:
loan = loan.replace("K", "000")
if "k" in loan:
loan = loan.replace("k", "000")
loan = float(loan)
interest_rate = float(input("Enter interest rate: ").strip('%').replace(',' ,''))
interest = get_number(loan, interest_rate)
print()
result = lc.setlocale(lc.LC_ALL, "")
if result == "C":
lc.setlocale(lc.LC_ALL, "en_US")
print(line.format("Loan amount:", lc.currency(loan, grouping=True)))
print(line.format("Interest rate:", str(interest_rate) + "%"))
print(line.format("Interest amount:", lc.currency(interest, grouping=True)))
print()
choice = input("Continue? (y/n): ")
print()
if choice == "n":
print("Bye!")
if __name__ == "__main__":
main()
Create a program that calculates the interest on a loan. This program should make it easy for the user to enter numbers. Console Interest Calculator Enter loan amount: Enter interest rate: $100,000 $2.275 Loan amount: Interest rate: Interest amount: Continue? (y/n): n Loan amount: Interest rate: Interest amount: Continue? (y/n): y Enter loan amount: 100K Enter interest rate: 2.275 $100,000.00 2.275% $2,275.00 $100,000.00 2.275% $2,275.00 Bye! Specifications Use the Decimal class to make sure that all calculations are accurate. The program should round the interest that's calculated to two decimal places, rounding up if the third decimal place is five or greater. The interest rate that's displayed can have up to 3 decimal places. Assume that the user will enter valid decimal values for the loan amount and interest rate with these exceptions: If the user enters a dollar sign (S) at the beginning of the loan amount, remove it from the string before converting the string to a number. If the user enters a comma in the loan amount, remove it from the string before converting the string. If the user enters a K at the end of the loan amount, remove the K from the end of the string, and multiply the loan amount by 1000. For example, a loan amount of 50K should be converted to a value of 50,000. If the user enters a percent sign (%) before or after the interest rate, remove it from the string before converting the string to a number.
Step by Step Solution
3.36 Rating (159 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
