If/while loop question in function

Hi everyone, I am currently writing a mini game in Python for me to exercise my skills and facing a problem related to if/while loop in function.

def next_year(player):
    player.new_year
    decision = input('How are you going to develop yourself in the coming year? A) Train Hard. B) Developing yourself in front of the media. Please type in the corrosponding letter.')
    while (decision != 'A' and decision != 'B'):
        decision == input('We have not received your decision. Please select again.')
    if player.stamina < 0:
        decision = input('Thank you for playing this game!')
        print(player)
    if decision == 'A':
        player.train_hard()
        print(player.stamina)
        next_year(player)
    elif decision == 'B':
        player.promote()
        next_year(player)

In the above function, I am hoping that everytime when someone input the wrong letter, it would show the error sentence until the player fill in the correct one, like the one below:

player_position = input('HI' + player_name + 'What position do you play? GK, DEF, MID, FWD?')
while player_position != 'GK' and player_position != 'DEF' and player_position != 'MID' and player_position != 'FWD':
    player_position = input('Seems like you have not selected a correct position, please select again.')

It worked outside the function, but it was stuck in ‘We have not received your decision’’ even after I type in the correct letter. How can I make it work within a function? What did I miss that caused this problem?

Thank You so much.

Hi,
Spot the difference between the third line of your code and the fifth…

you’ve an extra = inside the while loop, so it’s a comparison rather than an assignment

hope that helps

You are right. Very stupid mistake by me. smh haha

1 Like