Mar-19-2021, 10:58 AM
It works! But I have one question: When I programmed in C many years ago, the "user1 != "rock"...." line worked perfectly and also worked when I played with BASIC back in the day. Why doesn't it work with Python? Why do I have to resort to creating a list and executing the while statement or even the for statement from a list?
(Mar-18-2021, 02:26 PM)BashBedlam Wrote: I would make a separate function to keep looping until it got a valid input and then return that string, like this:
def get_valid_input (player) : acceptable_answers = ('rock', 'paper', 'scissors') prompt = ", you are up, what's it going to be, rock, paper or scissors? " answer = 'BashBedlam was here.' while answer not in acceptable_answers : answer = input ('\n' + player + prompt) answer = answer.lower () return answer def start(): player1 = input("Player one, What is your name? ") player2 = input("Player two, What is your name? ") user1 = get_valid_input (player1) user2 = get_valid_input (player2) return (player1, user1, player2, user2) print (start ())