简体   繁体   中英

Clarification on input

I was using code from someone else to make a compounding interest calculator in python. My question is on the second input "n" it asks for a string, but wants an integer and it gives no examples on how to answer the question. What should I put if the interests are compounded daily?

P = int(input("Enter starting principle please. "))
n = int(input("Enter Compound interest rate.(daily, monthly, quarterly, half-year, yearly) "))
r = float(input("Enter annual interest amount. (decimal) "))
t = int(input("Enter the amount of years. "))

final = P * (((1 + (r/(100.0 * n))) ** (n*t)))

print ("The final amount after", t, "years is", final)
P = int(input("Enter starting principle please. "))

n_str = input("Enter Compound interest rate.(daily, monthly, quarterly, half-year, yearly) ")
n_lookup = {"daily":356, "monthly":12, "quarterly":4, "half-yearly":2, "yearly":1}
n = n_lookup.get(n_str, 0)

r = float(input("Enter annual interest amount. (decimal) "))
t = int(input("Enter the amount of years. "))

final = P * (((1 + (r/(100.0 * n))) ** (n*t)))

print ("The final amount after", t, "years is", final)

Check out a demo here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM