Moving points between 'pots'

Hi there,

I’m trying to design a small point allocation program, which lets you assign a point or points from a ‘main pot’ to 5 other ‘pots’ for lack of a better explanation.

I want it to allow you to move ‘x’ amount of points before the pot is empty and have it tell you how many points are left in the main pot after each point is moved.

Once the main pot is empty I’d then like it to provide the total of points in each of the 5 pots.

My problem is that the loop I’ve created, continues when you select one pot and fills that up; then stops.
I want to be able to have the option to change where the next point goes after each one.

Can anyone help me with this, I think I’m close; but I’m obviously missing something?

Well it would help to see your code. Paste it in between triple
backticks:

```
your code here
```

I would guess your loop bound is wrong, or not accurately reached (eg
you run until “the pot has zero points”, and some operation takes too
many points, making the pot size negative - loop bound not matched).

Typical loop for your problem:

potsize = 1000  # or whatever value
while potsize > 0:
    ... take some points away ...

Provided you always take more than zero points away and correctly
decrement potsize, this loop will terminate.

Maybe your code is doing things in a different way?

Oh, also put some print() calls in your loop to see what is happening to
your values - it can be illuminating.

Cheers,
Cameron Simpson cs@cskk.id.au

The code I have is as follows:

main_pot = 5
pot_a = 0
pot_b = 0

move_coin = input("Which pot do you want to place a coin? ")

while main_pot != 0:
print(move_coin)
if move_coin == “a”:
pot_a = pot_a + 1
main_pot = main_pot - 1
print(f"Pot A contains {pot_a} coins and the main pot has {main_pot} coins remaining")
print(move_coin)
if move_coin == “b”:
pot_b = pot_b + 1
main_pot = main_pot - 1
print(f"Pot B contains {pot_b} coins and the main pot has {main_pot} coins remaining")
print(move_coin)
if main_pot == 0:
print(f"There are no more coins to move. Pot A has {pot_a} coins in it and Pot B has {pot_b} coins in it")

Problem is, the ‘while’ function will repeat the initial input answer till all coins are gone from the main pot, but if I change it to ‘if’ it only does it once then ends the program.
What can I do to have it let me choose for each coin?

The code I have is as follows:

main_pot = 5
pot_a = 0
pot_b = 0

move_coin = input("Which pot do you want to place a coin? ")

while main_pot != 0:
    print(move_coin)
    if move_coin == "a":
        pot_a = pot_a + 1
        main_pot = main_pot - 1
        print(f"Pot A contains {pot_a} coins and the main pot has {main_pot} coins remaining")
        print(move_coin)
    if move_coin == "b":
        pot_b = pot_b + 1
        main_pot = main_pot - 1
        print(f"Pot B contains {pot_b} coins and the main pot has {main_pot} coins remaining")
        print(move_coin)
if main_pot == 0:
    print(f"There are no more coins to move. Pot A has {pot_a} coins in it and Pot B has {pot_b} coins in it")

Problem is, the ‘while’ function will repeat the initial input answer
till all coins are gone from the main pot, but if I change it to ‘if’
it only does it once then ends the program.

That is because “if” is not a loop.

What can I do to have it let me choose for each coin?

Put the move_coin= question inside the loop. As written it runs
exactly once, before the loop.

Also, notice that the only way to leave the loop is when
not(main_pot!=0) (the inversion of the loop condition). That means
that after the loop it must be the case that main_pot==0.

So you don’t need the “if” below the loop - it will always be true.

Cheers,
Cameron Simpson cs@cskk.id.au