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.
Broskis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
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: ")
0
The Problem associated in your code is method calling. you are not calling method like lower() you are calling method reference like lower. You could replace lower to lower().
Thamarai Kannan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.