I have a while loop that calls on three functions. The three functions work as intended and at the end it asks for a user input. If the user input is ‘n’ the loop is supposed to end, but it continues regardless of what I put.
Here’s my code:
yn = ""
while (yn.lower != "n"):
usr_choice = userChoice()
com_choice = compChoice()
winner(usr_choice, com_choice)
yn = input("Would you like to continue? y/n: ")
I’ve tried formatting the while loop in various ways and ensuring no variable names matched regardless of their location but I still can’t end the loop by typing n or N. If possible I’d like to have the while loop end with either n or no, but first I need to get it working.
>Solution :
The issue is that you’re not actually envoking the yn.lower method, you’re just comparing the function object to the string "n"
yn = ""
while (yn.lower() != "n"): # <<---- See yn.lower VS yn.lower()
usr_choice = userChoice()
com_choice = compChoice()
winner(usr_choice, com_choice)
yn = input("Would you like to continue? y/n: ")