Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Programmer: Swinefire
- # Date: 2-14-13
- # The purpose of this program is to calculate the interest earned on a sum of money over a period of time.
- # (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.)
- def main():
- print "This program calculates the interest earned on a sum of money over a period of time." # Explains the purpose of the program
- print
- # Asks user for needed information
- originalAmount = input("How much money will be earning interest? $") # Assigns user-inputted amount earning interest to a variable
- interestPercent = input("What is the interest rate (percent)? ") # Assigns the user-inputted interest rate to a variable
- 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
- # Prints entered information for accuracy
- print
- print "Original amount in bank: " + str(originalAmount)
- print "Interest rate: " + str(interestPercent) + "%"
- print "Years earning interest: " + str(years)
- print
- # Asks user if printed information is correct
- correctQuestion = raw_input("Does all of the information look correct (yes or no)? ")
- print
- if correctQuestion == "yes" or "Yes" or "YES":
- interestDecimal = (interestPercent * 0.01) # Converts the interest rate from a percentage to a decimal and assigns it to a variable
- interestAmount = (originalAmount * interestDecimal * years) # Calculates the earned interest and assigns it to a variable
- totalAmount = (originalAmount + interestAmount) # Adds the earned interest to the original amount and assigns the sum to a variable
- # Prints all final amounts
- print
- 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) + "."
- # Allows a chance to re-enter information if any was entered incorrectly
- elif correctQuestion == "no" or "No" or "NO":
- originalAmount = input("How much money will be earning interest? $") # Assigns new user-inputted amount earning interest to a variable
- interestPercent = input("What is the interest rate (percent)? ") # Assigns the new user-inputted interest rate to a variable
- 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
- # Prints entered information for accuracy
- print
- print "Original amount in bank: " + str(originalAmount)
- print "Interest rate: " + str(interestPercent) + "%"
- print "Years earning interest: " + str(years)
- print
- # Asks user if printed information is correct
- correctQuestion = raw_input("Does all of the information look correct (yes or no)? ")
- print
- if correctQuestion == "yes" or "Yes" or "YES":
- interestDecimal = (interestPercent * 0.01) # Converts the interest rate from a percentage to a decimal and assigns it to a variable
- interestAmount = (originalAmount * interestDecimal * years) # Calculates the earned interest and assigns it to a variable
- totalAmount = (originalAmount + interestAmount) # Adds the earned interest to the original amount and assigns the sum to a variable
- # Prints all final amounts
- print
- 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) + "."
- # Allows a chance to re-enter information if any was entered incorrectly
- elif correctQuestion == "no" or "No" or "NO":
- originalAmount = input("How much money will be earning interest? $") # Assigns new user-inputted amount earning interest to a variable
- interestPercent = input("What is the interest rate (percent)? ") # Assigns the new user-inputted interest rate to a variable
- 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
- # Prints entered information for accuracy
- print
- print "Original amount in bank: " + str(originalAmount)
- print "Interest rate: " + str(interestPercent) + "%"
- print "Years earning interest: " + str(years)
- print
- interestDecimal = (interestPercent * 0.01) # Converts the interest rate from a percentage to a decimal and assigns it to a variable
- interestAmount = (originalAmount * interestDecimal * years) # Calculates the earned interest and assigns it to a variable
- totalAmount = (originalAmount + interestAmount) # Adds the earned interest to the original amount and assigns the sum to a variable
- # Prints all final amounts
- print
- 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) + "."
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement