May-27-2020, 10:58 PM
I'm trying to make a rock paper scissors game with a piece of code that prevents the random function from choosing the same option more than twice but the code isn't working correctly. Any suggestions?
import random print("Welcome to ROCK PAPER SCISSORS!") selecter = random.randint(1, 3) computer_choice = "" computer_score = 0 player_score = 0 computer_choice_history = [] playing = True while_counter = 0 while playing: while_counter += 1 if computer_score == 2: playing = False elif player_score == 2: playing = False if while_counter > 2: print("while counter = " + str(while_counter)) print(computer_choice_history) if computer_choice_history[0] == computer_choice_history[1]: selecter = random.randint(1, 3) # computer and player choices player_choice = input("\nchoose rock, paper or scissors:\n") if selecter == 1: computer_choice = "rock" elif selecter == 2: computer_choice = "paper" elif selecter == 3: computer_choice = "scissors" print(computer_choice) computer_choice_history.append(selecter) # computer wins round if computer_choice == "rock" and player_choice == "scissors": computer_score += 1 print("computer score - " + str(computer_score)) print("your score - " + str(player_score)) elif computer_choice == "scissors" and player_choice == "paper": computer_score += 1 print("computer score - " + str(computer_score)) print("your score - " + str(player_score)) elif computer_choice == "paper" and player_choice == "rock": computer_score += 1 print("computer score - " + str(computer_score)) print("your score - " + str(player_score)) # If both chose the same if computer_choice == player_choice: print("Tie") # player wins round elif player_choice == "rock" and computer_choice == "scissors": player_score += 1 print("your score - " + str(player_score)) print("computer score - " + str(computer_score)) elif player_choice == "scissors" and computer_choice == "paper": player_score += 1 print("your score - " + str(player_score)) print("computer score - " + str(computer_score)) elif player_choice == "paper" and computer_choice == "rock": player_score += 1 print("your score - " + str(player_score)) print("computer score - " + str(computer_score)) if computer_score == 3: print("\nComputer wins, YOU LOSE") elif player_score == 3: print("\nCongrats You Win!") satisfaction = input("\nare you satisfied?\n") # fix selecter var, line 38#