Notification texts go here Contact Us Click here

The Rock, Paper, Scissors game in Python to play it infinitely

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

Program : The Rock, Paper, Scissors game in Python to play it infinitely:

def get_user_choice():
    user_choice = input("Enter your choice (rock, paper, or scissors): ").lower()
    while user_choice not in ["rock", "paper", "scissors"]:
        user_choice = input("Invalid choice. Please enter rock, paper, or scissors: ").lower()
    return user_choice
 
def generate_random_number(seed):
    return (seed * 1103515245 + 12345) & 0xFFFFFFFF
 
def get_computer_choice(seed):
    choices = ["rock", "paper", "scissors"]
    random_number = generate_random_number(seed)
    random_index = random_number % 3
    return choices[random_index], random_number
 
def determine_winner(user_choice, computer_choice):
    if user_choice == computer_choice:
        return "It's a tie!"
    elif (user_choice == "rock" and computer_choice == "scissors") or \
         (user_choice == "paper" and computer_choice == "rock") or \
         (user_choice == "scissors" and computer_choice == "paper"):
        return "You win!"
    else:
        return "Computer wins!"
 
if __name__ == "__main__":
    print("Welcome to Rock, Paper, Scissors!")
 
    random_seed = int(input("Enter a random seed (an integer): "))
    while True:
        user_choice = get_user_choice()
        computer_choice, random_seed = get_computer_choice(random_seed)
 
        print(f"Your choice: {user_choice}")
        print(f"Computer's choice: {computer_choice}")
 
        result = determine_winner(user_choice, computer_choice)
        print(result)
        #user select play again"yes" or "No" 
        play_again = input("Do you want to play again? (yes/no): ").lower()
        if play_again != "yes":
            print("Thanks for playing!")
            break
 
 
OUTPUT :
 
Welcome to Rock, Paper, Scissors!
Enter a random seed (an integer)5
Enter your choice (rock, paper, or scissors): paper
Your choice: paper
Computer's choice: scissors
Computer wins!
Do you want to play again? (yes/no): yes
Enter your choice (rock, paper, or scissors): paper
Your choice: paper
Computer'
s choice: scissors
Computer wins!
Do you want to play again? (yes/no): yes
Enter your choice (rock, paper, or scissors): paper
Your choice: paper
Computer's choice: rock
You win!
Do you want to play again? (yes/no): no 
Thanks for playing!

 

Description : - 
The game loop continues until the player decides to stop by entering "no" 
when asked if they want to play again. The random number generation is 
based on a simple linear congruential generator algorithm using the given seed.
This version of the game allows you to play infinitely and keeps track of 
the random seed for generating computer choices.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.