Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Pomoć oko programa - Future Value of Investment

[es] :: Python :: Pomoć oko programa - Future Value of Investment

[ Pregleda: 4027 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Pomoć oko programa - Future Value of Investment26.02.2017. u 16:29 - pre 86 meseci
Radim po knjizi Python Programming: An Introduction to Computer Science (2nd Edition) by John Zelle.

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.


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()


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.
 
Odgovor na temu

zema
hamburg

Član broj: 20112
Poruke: 71
109.122.106.*



+6 Profil

icon Re: Pomoć oko programa - Future Value of Investment26.02.2017. u 16:52 - pre 86 meseci
greska je u for petlji

Code:


for i in range(years * periods):
    principal += rate / periods


 
Odgovor na temu

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Re: Pomoć oko programa - Future Value of Investment26.02.2017. u 17:12 - pre 86 meseci
Mnogo mi ovo "malo"?

 
Odgovor na temu

zema
hamburg

Član broj: 20112
Poruke: 71
109.122.106.*



+6 Profil

icon Re: Pomoć oko programa - Future Value of Investment26.02.2017. u 17:43 - pre 86 meseci
Code:


principal = principal * (1 + (rate / periods))

 
Odgovor na temu

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Re: Pomoć oko programa - Future Value of Investment26.02.2017. u 17:46 - pre 86 meseci
Bravo :) hvala puno!
 
Odgovor na temu

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Re: Pomoć oko programa - Future Value of Investment26.02.2017. u 17:54 - pre 86 meseci
BTW:

Citat:
Any book telling you to use eval to convert input strings to numbers is incredibly wrong. Don't do that. Use int or float if you want those.


sa StackOverflow-a
 
Odgovor na temu

[es] :: Python :: Pomoć oko programa - Future Value of Investment

[ Pregleda: 4027 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.