Python 3.6 Requriements Submit only the files requested Print all floats to 2 de
ID: 3598675 • Letter: P
Question
Python 3.6
Requriements
Submit only the files requested
Print all floats to 2 decimal points unless stated otherwise
You MUST use loops to solve this problem
Restrictions
No global variables may be used
Your program must have at least 1 user defined function
Description
For this problem you will be figuring out if it is more beneficial to pay off your loans first before investing or if you should only make the minimum payments and invest the rest.
Some things to pay attention to
Interest rates given are annual interests rates but we will be assuming that interest is compounded monthly so the real rates to use will be 1/12 of what we are given
We will assume that interest is compounded on our accounts before any payments or contributions are made to them
If the user has not finished paying off all of their loans before they retire a warning message should be printed
Cautions about using this program for your own investment startegies
This program assumes you are putting your money in a Roth IRA
There is an easier way to solve this problem in real life. Remind me to tell you about it.
Assumptions
Input will not always be valid
If invalid input is received your program should continue to ask for more input until a valid value is entered
While input may be invalid it will always be of the correct type
Valid values for inputs
Loans: A real number >= 0
Annual loan interest rate: a real number >= 0
Minimum payment: a real number >= 0
Investment money: A real number >= minimum payment
Current age: an integer >= 0
Retirement age: an integer >= current age
Annual rate of return: a real number >= 0
Hints
This problem has no relationship to the monthly payment formula that we did in homework 1. Don't try and use it
Don't try and look up a closed form solution to this problem. I'm not sure if there is one and the program requires you to use loops, so if you find one you couldn't use it any way
When solving this problem think about what you would do in real life when paying off your loans / savings and have your program do that as well
Make sure that you handle the month where you fully pay off your loans correctly. During that month your loans might be less than your minimum payment
Examples
Example 1
Enter how much money you owe in loans: 40000
Enter the annual interest rate of the loans: 0.03
Enter your minimum monthly loan payment: 405.32
Enter how much money you will be putting towards loans/retirement each month: 500
Enter your current age: 22
Enter the age you plan to retire at: 65
Enter your predicted annual rate of return: .05
You should only make minimum payments on your loans and invest the rest
If you do you will have $592888.96 as opposed to $587281.54 when you retire.
Example 2
Enter how much money you owe in loans: 50000
Enter the annual interest rate of the loans: 0.06
Enter your minimum monthly loan payment: 350
Enter how much money you will be putting towards loans/retirement each month: 1053
Enter your current age: 25
Enter the age you plan to retire at: 70
Enter your predicted annual rate of return: 0.05
You should pay of all of your loans before you start investing
If you do you will have $1651149.44 as opposed to $1619732.68 when you retire.
Example 3
Enter how much money you owe in loans: 10000
Enter the annual interest rate of the loans: .02
Enter your minimum monthly loan payment: 100
Enter how much money you will be putting towards loans/retirement each month: 500
Enter your current age: 18
Enter the age you plan to retire at: 20
Enter your predicted annual rate of return: 0.07
Warning after you retire you will still have $7961.19 in loans left.
You should only make minimum payments on your loans and invest the rest
If you do you will have $10272.41 as opposed to $1835.38 when you retire.
Example 4
Enter how much money you owe in loans: -3
Enter how much money you owe in loans: -2
Enter how much money you owe in loans: 25000
Enter the annual interest rate of the loans: -2
Enter the annual interest rate of the loans: -8
Enter the annual interest rate of the loans: -17
Enter the annual interest rate of the loans: .04
Enter your minimum monthly loan payment: -3
Enter your minimum monthly loan payment: 500
Enter how much money you will be putting towards loans/retirement each month: 2
Enter how much money you will be putting towards loans/retirement each month: 5
Enter how much money you will be putting towards loans/retirement each month: 300
Enter how much money you will be putting towards loans/retirement each month: 600
Enter your current age: -9
Enter your current age: 25
Enter the age you plan to retire at: 12
Enter the age you plan to retire at: 13
Enter the age you plan to retire at: 68
Enter your predicted annual rate of return: -9
Enter your predicted annual rate of return: .03
You should pay of all of your loans before you start investing
If you do you will have $538083.32 as opposed to $537722.67 when you retire.
Explanation / Answer
#Initializing global variables
str_ciph = ""
shft_amnt = 0
ciphered = ""
order = 0
#While condition to run in an infinite loop until user enters valid inputs
while(True):
str_ciph = raw_input("Please enter a string to be ciphered: ")
shft_amnt = input("Please enter a shift amount between 0 and 25: ")
#Checking for invalid inputs
if(any(str.isdigit(c) for c in str_ciph) == True or shft_amnt>25 or shft_amnt<0):
continue;
else:
break;
#Loop to generate ciphered text
for c in str_ciph:
if(ord(c)>=65 and ord(c)<=90): #Shifting uppercase characters
order = ord(c)+shft_amnt
if(order>90):
order = order-90+65-1
ciphered = ciphered+chr(order)
if(ord(c)>=97 and ord(c)<=122): #Shifting lowercase characters
order = ord(c)+shft_amnt
if(order>122):
order = order-122+97-1
ciphered = ciphered+chr(order)
print ciphered
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.