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?
JavaScript
x
13
13
1
import random
2
3
choices = ["Rock", "Scissors", "Paper"]
4
5
computer = random.choice(choices)
6
player = None
7
8
while player not in choices:
9
player = input("rock, scissors, or paper?").lower()
10
11
print("Computer: ",computer)
12
print("Player: ",player)
13
Advertisement
Answer
The correct code would be
JavaScript
1
13
13
1
import random
2
3
choices = ["Rock", "Scissors", "Paper"]
4
5
computer = random.choice(choices)
6
player = None
7
8
while player not in choices:
9
player = input("Rock, scissors, or paper?").capitalize()
10
11
print("Computer: ",computer)
12
print("Player: ",player)
13