I'm new to Python, and I have an assignment where I have a frogs vs. toads game. They are in a list and they need to swap places one step at a time.
the list looks like this: ["F","F","F"," ","T","T","T"]
and should look like ["T","T","T"," ","F","F","F"]
to win the game. The user inputs From
and To
and they swap. But my code is not taking the swapped code as the new code when the new From
and To
are being entered. How do I fix this?
This is all within a while loop as there are other options at the beginning of the game.
Also, one of the rules for the assignment is that the frogs are only allowed to one one direction to the left and the toads vice versa. if anyone knows how to put that into my code that would be very much appreciated.
Here's my code:
elif choice== 'P':
position= ["1","2","3","4","5","6","7"]
frogsandtoads= ["F","F","F"," ","T","T","T"]
print("Position: ",position)
print("Lilypad: ",frogsandtoads)
def swappositions(frogsandtoads, pos1, pos2):
if pos1== 'e':
exit()
if pos1== 'E':
exit()
frogsandtoads[pos1], frogsandtoads[pos2] = frogsandtoads[pos2], frogsandtoads[pos1]#the swapping of the positions
return frogsandtoads
pos1 = fromplace= int(input("From: "))
pos2 = toplace= int(input("To: "))
print(swappositions(frogsandtoads, pos1-1, pos2-1))
frogsandtoads=swappositions(frogsandtoads, pos1-1, pos2-1)
if frogsandtoads== ["T","T","T"," ","F","F","F"]: #this is what is not working
break
this is my outcome when I run the code:
Please choose an option: p
Position: ['1', '2', '3', '4', '5', '6', '7']
Lilypad: ['F', 'F', 'F', ' ', 'T', 'T', 'T']
From: 3
To: 4
['F', 'F', ' ', 'F', 'T', 'T', 'T']
Position: ['1', '2', '3', '4', '5', '6', '7']
Lilypad: ['F', 'F', 'F', ' ', 'T', 'T', 'T']
From:
As you can see I don't know how to make it so the lilypad changes with the input of the from and to the second time round.