Reputation: 71
I cannot figure out why my while loop won't terminate my game after user_count
or comp_count
reaches 3
.
Would anyone please be able to offer some advice? I don't see what I am missing as I have everything indented under the while loop, and I am incrementing scores +=1 with each turn that is played.
import random
rock_paper_scissor_list = ['ROCK', 'PAPER', 'SCISSORS']
def comp_turn():
comp_choice = random.choice(rock_paper_scissor_list)
return comp_choice
def user_turn():
raw_user_input = input('Choose rock/paper/scissors: ').lower()
if raw_user_input in ['rock', 'r']:
user_choice = 'ROCK'
elif raw_user_input in ['paper', 'p']:
user_choice = 'PAPER'
else:
user_choice = 'SCISSORS'
return user_choice
def play_game(user_choice, comp_choice):
user_score = 0
comp_score = 0
print('User choice is: ' + user_choice)
print('Comp choice is: ' + comp_choice + '\n')
while user_score < 3 or comp_score < 3:
if comp_choice == 'ROCK' and user_choice == 'ROCK':
print("It's a tie!")
elif comp_choice == 'PAPER' and user_choice == "ROCK":
print('Comp wins this round!')
comp_score += 1
elif comp_choice == 'SCISSORS' and user_choice == "ROCK":
print('You win this round!')
user_score += 1
elif comp_choice == 'ROCK' and user_choice == "PAPER":
print('You win this round!')
user_score += 1
elif comp_choice == 'PAPER' and user_choice == "PAPER":
print("It's a tie!")
elif comp_choice == 'SCISSORS' and user_choice == "PAPER":
print('Comp wins this round!')
comp_score += 1
elif comp_choice == 'ROCK' and user_choice == "SCISSORS":
print('Comp wins this round!')
comp_score += 1
elif comp_choice == 'PAPER' and user_choice == "SCISSORS":
print('You win this round!')
user_score += 1
elif comp_choice == 'SCISSORS' and user_choice == "SCISSORS":
print("It's a tie!")
print('\nUser score is: ' + str(user_score))
print('Comp score is: ' + str(comp_score))
play_game(user_turn(), comp_turn())
Upvotes: 1
Views: 131
Reputation: 45750
user_score < 3 or comp_score < 3
will be true until both scores are greater than or equal to 3. You want and
to ensure that both are under 3:
while user_score < 3 and comp_score < 3:
Upvotes: 1