Advertisement
swinefire

Simple Interest Calculator

Feb 14th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.68 KB | None | 0 0
  1. # Programmer: Swinefire
  2. # Date: 2-14-13
  3.  
  4. # The purpose of this program is to calculate the interest earned on a sum of money over a period of time.
  5. # (It also provides two extra opportunities for the user to enter the data correctly without restarting the program if they make a mistake while entering it.)
  6.  
  7. def main():
  8.  
  9.     print "This program calculates the interest earned on a sum of money over a period of time."    # Explains the purpose of the program
  10.     print
  11.  
  12.     # Asks user for needed information
  13.     originalAmount = input("How much money will be earning interest? $")    # Assigns user-inputted amount earning interest to a variable
  14.     interestPercent = input("What is the interest rate (percent)? ")        # Assigns the user-inputted interest rate to a variable
  15.     years = input("How many years will the money be earning money? ")       # Assigns the user-inputted number of years the money will be earning interest to a variable
  16.  
  17.     # Prints entered information for accuracy
  18.     print
  19.     print "Original amount in bank: " + str(originalAmount)
  20.     print "Interest rate: " + str(interestPercent) + "%"
  21.     print "Years earning interest: " + str(years)
  22.     print
  23.  
  24.     # Asks user if printed information is correct
  25.     correctQuestion = raw_input("Does all of the information look correct (yes or no)? ")
  26.     print
  27.  
  28.     if correctQuestion == "yes" or "Yes" or "YES":
  29.  
  30.             interestDecimal = (interestPercent * 0.01)                      # Converts the interest rate from a percentage to a decimal and assigns it to a variable
  31.             interestAmount = (originalAmount * interestDecimal * years)     # Calculates the earned interest and assigns it to a variable
  32.             totalAmount = (originalAmount + interestAmount)                 # Adds the earned interest to the original amount and assigns the sum to a variable
  33.  
  34.             # Prints all final amounts
  35.             print
  36.             print "If $" + str(originalAmount)  + " earns " + str(interestPercent) + "% interest for " + str(years) + " years, it would earn a total of $" + str(interestAmount) + " in interest, giving you a total of $" + str(totalAmount) + "."
  37.  
  38.     # Allows a chance to re-enter information if any was entered incorrectly
  39.     elif correctQuestion == "no" or "No" or "NO":
  40.  
  41.         originalAmount = input("How much money will be earning interest? $")    # Assigns new user-inputted amount earning interest to a variable
  42.         interestPercent = input("What is the interest rate (percent)? ")        # Assigns the new user-inputted interest rate to a variable
  43.         years = input("How many years will the money earn interest? ")          # Assigns the new user-inputted number of years the money will be earning interest to a variable
  44.  
  45.         # Prints entered information for accuracy
  46.         print
  47.         print "Original amount in bank: " + str(originalAmount)
  48.         print "Interest rate: " + str(interestPercent) + "%"
  49.         print "Years earning interest: " + str(years)
  50.         print
  51.  
  52.         # Asks user if printed information is correct
  53.         correctQuestion = raw_input("Does all of the information look correct (yes or no)? ")
  54.         print
  55.    
  56.         if correctQuestion == "yes" or "Yes" or "YES":
  57.        
  58.                 interestDecimal = (interestPercent * 0.01)                  # Converts the interest rate from a percentage to a decimal and assigns it to a variable
  59.                 interestAmount = (originalAmount * interestDecimal * years) # Calculates the earned interest and assigns it to a variable
  60.                 totalAmount = (originalAmount + interestAmount)             # Adds the earned interest to the original amount and assigns the sum to a variable
  61.  
  62.                 # Prints all final amounts
  63.                 print
  64.                 print "If $" + str(originalAmount)  + " earns " + str(interestPercent) + "% interest for " + str(years) + " years, it would earn a total of $" + str(interestAmount) + " in interest, giving you a total of $" + str(totalAmount) + "."
  65.  
  66.         # Allows a chance to re-enter information if any was entered incorrectly
  67.         elif correctQuestion == "no" or "No" or "NO":
  68.        
  69.             originalAmount = input("How much money will be earning interest? $")    # Assigns new user-inputted amount earning interest to a variable
  70.             interestPercent = input("What is the interest rate (percent)? ")        # Assigns the new user-inputted interest rate to a variable
  71.             years = input("How many years will the money earn interest? ")          # Assigns the new user-inputted number of years the money will be earning interest to a variable
  72.  
  73.             # Prints entered information for accuracy        
  74.             print
  75.             print "Original amount in bank: " + str(originalAmount)
  76.             print "Interest rate: " + str(interestPercent) + "%"
  77.             print "Years earning interest: " + str(years)
  78.             print
  79.            
  80.             interestDecimal = (interestPercent * 0.01)                      # Converts the interest rate from a percentage to a decimal and assigns it to a variable
  81.             interestAmount = (originalAmount * interestDecimal * years)     # Calculates the earned interest and assigns it to a variable
  82.             totalAmount = (originalAmount + interestAmount)                 # Adds the earned interest to the original amount and assigns the sum to a variable
  83.  
  84.             # Prints all final amounts
  85.             print
  86.             print "If $" + str(originalAmount)  + " earns " + str(interestPercent) + "% interest for " + str(years) + " years, it would earn a total of $" + str(interestAmount) + " in interest, giving you a total of $" + str(totalAmount) + "."
  87.  
  88.                    
  89. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement