##Interest calculator 10-3 from decimal import Decimal from decimal import ROUND_HALF_UP import locale as lc #locale.setlocale(locale.LC_ALLl, us)...
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()
#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()
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch