Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how do i rewrite this code to give me 10 outputs
#1
# 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()
Quote
#2
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
Quote
#3
(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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Interpreter and running a .py file give different outputs PythonNPC 5 269 Jul-21-2019, 01:07 PM
Last Post: PythonNPC
  Rewrite a function to make it work with 'bottle-pymysql' nikos 1 235 Feb-26-2019, 02:59 PM
Last Post: nikos
  My code is taking longer time to give result rajeshwin 4 380 Feb-20-2019, 08:18 PM
Last Post: ichabod801
  piexif rewrite exif data yawstick 2 644 Oct-09-2018, 08:56 PM
Last Post: yawstick
  Not having to rewrite 'obj.' on each line beuaaa 4 577 Sep-30-2018, 02:21 AM
Last Post: micseydel
  Save outputs to Desktop cisicomania 1 515 Aug-31-2018, 10:08 AM
Last Post: Gribouillis
  Help Editing/Problem with outputs stanthaman42 7 902 Jul-11-2018, 05:30 PM
Last Post: ichabod801
  How to rewrite image file name based on ocr data.txt kevinchr 0 863 Apr-16-2018, 07:09 PM
Last Post: kevinchr
  Rewrite variable every n times andrea0913 0 851 Aug-20-2017, 05:54 PM
Last Post: andrea0913
  Different outputs in Python2 and Python3 MikeHill 3 1,576 Jun-07-2017, 08:58 PM
Last Post: Ofnuts

Forum Jump:


Users browsing this thread: 1 Guest(s)