W.Kumar
W.Kumar

Reputation: 1

How do I surpass a certain amount and show it?

This is my programme, this is where pocket money doubles each week. How do I show which week it will reach or surpass £100?

pocketMoney = 0.01

totalMoney = 0

week=0

for week in range(1,27):
    week=week+1

    print("It is week ",week)

    print("You will get £ ",pocketMoney)
    pocketMoney= pocketMoney*2
    totalMoney = pocketMoney-0.01

    if pocketmoney>=100:
        print("It will be",week,"to get £100")

    else:
        print("It will be",week,"to get £100")   
        print("Your total amount of money is",totalMoney)

It keeps on going wrong. I've tried several times and I do not understand! I feel like it is so basic but I don't know where I went wrong!

Upvotes: 0

Views: 433

Answers (2)

Weston Reed
Weston Reed

Reputation: 187

Python cares about indents, so make sure you're mindful of that. I'm assuming you want to quit once you've hit >100, so I've added a break statement there.

Here's what your code should look like:

pocketMoney=0.01
totalMoney=0
week=0

for week in range(1,27):

    print("It is week", week)

    print("You will get £",pocketMoney)
    pocketMoney=pocketMoney*2
    totalMoney=pocketMoney-0.01

    if pocketMoney>=100:
        print("It will be", week," to get £100")
        break;

print("Your total amount of money is £",totalMoney)

Edit: I've removed the week=week+1 part because this is a for loop, so that isn't needed.

Upvotes: 2

Joe Patten
Joe Patten

Reputation: 1704

Here is my code:

pocketMoney = 0.01
totalMoney = 0

for week in range(1,27):
    print("It is week "+str(week)+".")
    print("You will get £"+str(pocketMoney)+".")
    pocketMoney= pocketMoney*2
    totalMoney = pocketMoney-0.01
    if pocketMoney>=100:    
        print("It will be "+str(week)+" weeks to get £100.")    
        break   
print("Your total amount of money is £"+str(totalMoney)+".")

I took out week=0 and week=week+1 as they are not needed. I also formatted the printed a bit.

Upvotes: 0

Related Questions