Skip to content
Advertisement

How can I end the while loop in my code below? [closed]

I am a python beginner. I’ve written a code but it can not get out of the loop. It keeps prompting the user for a choice. I want it to take the input and then proceed to print(). Could anyone please tell me how I can end the while loop after taking the input?

import random

choices = ["Rock", "Scissors", "Paper"]

computer = random.choice(choices)
player = None

while player not in choices:   
    player = input("rock, scissors, or paper?").lower()  

print("Computer: ",computer)
print("Player: ",player)

Advertisement

Answer

The correct code would be

import random

choices = ["Rock", "Scissors", "Paper"]

computer = random.choice(choices)
player = None

while player not in choices:   
    player = input("Rock, scissors, or paper?").capitalize()  

print("Computer: ",computer)
print("Player: ",player)
Advertisement