Ne mogu da se snađem oko 7. zadatka na 43. strani:
Citat:
As an alternative to APR, the interest accrued on an account is often described in terms of a nominal rate and the number of compounding periods. For example, if the interest rate is 3% and the interest is compounded quarterly, the account actually earns 3/4 % interest every 3 months.
Modify the futval.py program to use this method of entering the interest rate. The program should prompt the user for the yearly rate (rate) and the number of times that the interest is compounded each year (periods). To compute the value in ten years, the program will loop 10 * periods times and accrue rate/period interest on each iteration.
Modify the futval.py program to use this method of entering the interest rate. The program should prompt the user for the yearly rate (rate) and the number of times that the interest is compounded each year (periods). To compute the value in ten years, the program will loop 10 * periods times and accrue rate/period interest on each iteration.
Pokušavam to da uradim na sledeći način:
Code:
# futval.py
# A program to compute the value of an investment
# carried n years into the future
def main():
print("This program calculates the future value of a n-year investment.")
print()
principal = eval(input("Enter the initial principal: "))
initial = principal
rate = eval(input("Enter the interest rate: "))
years = eval(input("Enter the number of years: "))
periods = eval(input("Enter the number of times that the interest is compounded each year: "))
for i in range(years * periods):
principal = rate / periods
print("The value in " + str(years) + " years is:", principal)
print("The accumulation in " + str(years) + " years is: " + str(principal - initial))
main()
# futval.py
# A program to compute the value of an investment
# carried n years into the future
def main():
print("This program calculates the future value of a n-year investment.")
print()
principal = eval(input("Enter the initial principal: "))
initial = principal
rate = eval(input("Enter the interest rate: "))
years = eval(input("Enter the number of years: "))
periods = eval(input("Enter the number of times that the interest is compounded each year: "))
for i in range(years * periods):
principal = rate / periods
print("The value in " + str(years) + " years is:", principal)
print("The accumulation in " + str(years) + " years is: " + str(principal - initial))
main()
Malo sam zaobišao instrukcije kada je reč o tačnom broju godina (10) - ostavio sam mogućnost da i za to bude unešen broj godina. Takođe, dodao sam opciju da se na kraju izlista koliko je novca akumulirano. Elem, problem mi pravi konkretna formula - da li neko kompetentniji može da mi pomogne?
Hvala unapred.