Guest User

Untitled

a guest
Nov 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # display a welcome message
  4. print("Welcome to the Future Value Calculator")
  5. print()
  6.  
  7. choice = "y"
  8. while choice.lower() == "y":
  9.  
  10.  
  11. # get input from the user
  12. while True:
  13. monthly_investment = float(input("Enter monthly investment:\t"))
  14. if monthly_investment > 0:
  15. break
  16. else:
  17. print("Entry must be greater than 0. Please try again.")
  18. while True:
  19. yearly_interest_rate = float(input("Enter yearly interest rate:\t"))
  20. if yearly_interest_rate > 0 and yearly_interest_rate <= 15:
  21. break
  22. else:
  23. print("Entry must be greater than 0 and less than or equal to 15. Please try again.")
  24. while True:
  25. years = int(input("Enter number of years:\t\t"))
  26. if years > 0 and years <= 50:
  27. break
  28. else:
  29. print("Entry must be greater than 0 and less than or equal to 50. Please try again.")
  30.  
  31. # convert yearly values to monthly values
  32. monthly_interest_rate = yearly_interest_rate / 12 / 100
  33. months = years * 12
  34.  
  35.  
  36. # calculate the future value
  37. future_value = 0
  38. counter = 1
  39.  
  40. for i in range(months):
  41. future_value += monthly_investment
  42. monthly_interest_amount = future_value * monthly_interest_rate
  43. future_value += monthly_interest_amount
  44.  
  45. if counter == 12:
  46. print("Year = " + str((i % 11) + 1) + " Future value = " + str(round(future_value, 2)))
  47. counter = 0
  48.  
  49. counter += 1
  50.  
  51. # display the result
  52. #print("Future value:\t\t\t" + str(round(future_value, 2)))
  53. print()
  54.  
  55. # see if the user wants to continue
  56. choice = input("Continue (y/n)? ")
  57. print()
  58.  
  59. print("Bye!")
Add Comment
Please, Sign In to add comment