Reputation: 69
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
.
Upvotes: 2
Views: 514
Reputation: 6179
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) )
Upvotes: 4
Reputation: 7100
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)
Upvotes: 1