import random ai_choice = ["rock", "paper", "scissors"] def win_or_lose (player_move, ai_move, tie_score, player_score, ai_score): # calculating who's going to win if player_move == ai_move: print("You Tied") tie_score += 1 elif (player_move == "rock" and ai_move == "scissors" or player_move == "scissors" and ai_move == "paper" or player_move == "paper" and ai_move == "rock"): print("You Won!") player_score += 1 else: print("You Lose!") ai_score += 1 return player_score, tie_score, ai_score def getting_player_move(): while True: move_input = "Rock, Paper, Scissors, or exit? " player_move = input(move_input).lower().strip() if player_move == "scissor": player_move = "scissors" if player_move not in ["rock", "paper", "scissors", "exit"]: print("Invalid input. Choose Rock, Paper, or Scissors.") else: return player_move #game code name=input("what is your name? ") print("Welcome to Rock paper scissors",name) #this code checks if the user wants the rules or not while True: rules=input("Do you want to see how to play?(yes/no) ").lower() if rules in ("yes", "y"): print(" ---- rules ----") print("First, you select a move to play (rock, paper, or scissors).") print("At the same time, your opponent will pick a move.") print("The order of victory goes as follows:") print("Rock beats scissors, scissors beats paper and paper beats rock") print("If you pick the same move, you tie") print("That's all the rules, enjoy the game :).") elif rules in ["no","n"]: print("I worked hard on them, But you can skip them if you want to.") else: print("come again? (yes/no)") continue while True: #seeing if the player wants to do a certain number of rounds or infinite choices = input("Would You like to play to a set amount of win or infinity mode?(rounds or infinity) ").lower() if choices == "infinity" or choices == "infinite": player_score = 0 ai_score = 0 tie_score = 0 while True: #ai coding ai_move = random.choice(ai_choice) #player input player_move = getting_player_move() # exit code if player_move == "exit": print("The score is:", "Your wins", player_score, "| Ties", tie_score, "| AI wins", ai_score) print("Thanks for playing") break # announcing the moves print("rock paper scissors shoot") print("You:", player_move.capitalize()) print("AI:", ai_move.capitalize()) player_score, tie_score, ai_score = win_or_lose(player_move, ai_move, tie_score, player_score, ai_score) elif choices == "round" or choices == "rounds": while True: player_score = 0 ai_score = 0 tie_score = 0 rounds_number = input("How many wins? ") if not rounds_number.isdigit() or int(rounds_number) <= 0: print("Invalid input or choose a number greater than 0.") continue rounds = int(rounds_number) while player_score < rounds and ai_score < rounds: #ai coding ai_move = random.choice(ai_choice) #player input player_move = getting_player_move() # exit code if player_move == "exit": print("The score is:", "Your wins", player_score, "| Ties", tie_score, "| AI wins", ai_score) print("Thanks for playing") break #announcing the moves print("rock paper scissors shoot") print("You:", player_move.capitalize()) print("AI:", ai_move.capitalize()) player_score, tie_score, ai_score = win_or_lose(player_move, ai_move, tie_score, player_score, ai_score) print("The score is:","Your wins",player_score,"Ties", tie_score,"AI wins", ai_score) break else: print("Invalid input choose a number or infinity.")