2

I have to write a program in python about this problem:

Ask the user for an initial balance for their holiday club savings account. The user is to be prompted for 11 deposit amounts. Output the final amount in the account.

This is what I have so far and I am lost. I don't know what to add in order to get the final amount. I also don't know how to make the numbers for the 11 deposits show.

balance = int(input("Enter initial balance: $"))
count = 1
numDep = 11
finalAmount = balance+numDep
while count <= 11:
    n = int(input("Enter deposit #:")) # this needs to show deposits numbers up to 11
    count += 1

print("Original price: $", balance)
print("Final Amount: $", finalAmount)

That is all I have for writing the program using a while-loop. I still need to write it using for-loop.

2
  • 1
    why are adding 11 to numDep ? Commented Oct 7, 2015 at 3:45
  • finalAmount=12 would be exactly the same as what you have ... since you are never changing it im sure it always orints 12 Commented Oct 7, 2015 at 3:49

2 Answers 2

4

You need to find the total.

balance = int(input("Enter initial balance: $ "))
count = 1
total =0
while count <= 11:
    n = int(input("Enter deposit %s #: " %(count))) 
    count += 1
    total += n #keep on adding deposit amounts.


print("Original price: $ %d" %balance)
print("Final Amount: $ %d" %(total + balance) )

With For loop:

balance = int(input("Enter initial balance: $ "))
for i in range(11):
    n = int(input("Enter deposit #: %s " %(i)))
    total +=n

print("Original price: $ %d" %balance)
print("Final Amount: $ %d" %(total + balance) )
Sign up to request clarification or add additional context in comments.

12 Comments

He asked for it as a for loop. And, for i in range(11) will iterate 11 times.
but to me his while loop implementation seems wrong. He initially did ask for both.
The while loop implementation was wrong. This is a bad use of a while loop (the general problem).
"Enter deposit #%s: " %str(count)
@intboolstring he did want to have 11 deposits. So range(11) seems good to me.
|
1

Here it is using a for loop.

balance = int(input("Enter the initial balance"))
beginning = balance
for i in range(1,11):
    n = int(input(("Deposit"+str(i))))
    balance += n
print("You had", beginning, "at the beginning")
print("Now, you have", balance)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.