Skip to content

Instantly share code, notes, and snippets.

@Kwisses
Last active March 9, 2016 00:58
Show Gist options
  • Save Kwisses/10f704792350277885db to your computer and use it in GitHub Desktop.
Save Kwisses/10f704792350277885db to your computer and use it in GitHub Desktop.
[Daily Challenge #2 - Easy] - Calculator App - r/DailyProgrammer
# ***** DAILY CHALLENGE #2 - Easy *****
# Hello, coders! An important part of programming is being able to apply your programs, so your challenge for today is
# to create a calculator application that has use in your life. It might be an interest calculator, or it might be
# something that you can use in the classroom.
#
# For example, if you were in physics class, you might want to make a F = M * A calc.
#
# EXTRA CREDIT: make the calculator have multiple functions! Not only should it be able to calculate
# F = M * A, but also A = F/M, and M = F/A!
# ---------------------------------------------------------------------------------------------------------------------
def monthly_interest_calc(money, months, interest_rate):
"""Calculates simple monthly interest via x money, y months, and z interest in %.
Args:
money (float): Base amount of money to calculate.
months (int): Time in months to calculate interest accumulated.
interest_rate (float): Interest rate per month in percentage.
Return:
float: money + calculated interest
"""
interest = interest_rate / 100
interest_calc = interest * money * months
result = money + interest_calc
return round(result, 2)
def main():
try:
amount = float(input("Amount of Money: "))
time = int(input("Number of Months: "))
rate = float(input("Interest Rate in Percent: "))
calc = monthly_interest_calc(amount, time, rate)
print("\n$%.2f in %s Months at %.2f percent interest per month:\nTotal: $%.2f" % (amount, time, rate, calc))
except ValueError:
print("ERROR: input not valid. Try again.")
main()
if __name__ == "__main__":
main()
@Kwisses
Copy link
Author

Kwisses commented Mar 2, 2016

[Daily Challenge #2 - Easy] from the DailyProgrammer subreddit. Monthly Interest Calculator. No bonus.

Reference: https://www.reddit.com/r/dailyprogrammer/comments/pjbj8/easy_challenge_2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment