Python Forum
how do i rewrite this code to give me 10 outputs - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: how do i rewrite this code to give me 10 outputs (/thread-9245.html)



how do i rewrite this code to give me 10 outputs - BlackPimpernel - Mar-29-2018

# File: Futurevalue.py
# A simple program illustrating the future value of a savings account in 10 years
def main():
    p = eval(input ("Enter the initial principal amount in the savings account: "))
    apr = eval(input ("Enter the annual interest rate: " ))
    for i in range(10):
        p = p*(1 + apr)
                                 
    print("The value in 10 years is:", p)
    


main()



RE: how do i rewrite this code to give me 10 outputs - Larz60+ - Mar-29-2018

your print statement is outside the loop.
Add 4 spaces before the print, thus making it part of the loop and you will see 10 outputs


RE: how do i rewrite this code to give me 10 outputs - BlackPimpernel - Mar-29-2018

(Mar-29-2018, 04:24 AM)Larz60+ Wrote: your print statement is outside the loop.
Add 4 spaces before the print, thus making it part of the loop and you will see 10 outputs

That works. Thank you