souravjain540 / Basic-Python-Programs

This repository will contain basic python programming questions and their solutions.
270 stars 391 forks source link

# RocksPapersScissors #449

Open PavanCheruvupally opened 10 months ago

PavanCheruvupally commented 10 months ago
          # RocksPapersScissors

“Rock paper scissors” is a simple and interesting game. Many of us used to play it in a school to resolve disputes or just to spend some time.

RULES: The rules are very simple and probably you remember them from your childhood:

-> If you choose Rock, you will win against Scissors but lose against Paper.

-> If you choose Scissors, you will win against Paper but lose against Rock.

-> If you choose Paper, you will win against Rock but lose against Scissors.

Originally posted by @PavanCheruvupally in https://github.com/souravjain540/Basic-Python-Programs/pull/448#pullrequestreview-1749267429

Robot403 commented 10 months ago

import random

game = True

score = 0

valid_inputs = ["rock", "paper", "scissors"]

print("Welcome to Rock. Paper, Scissors. Let's play best 2 of 3")

while game is True: while -2 < score < 2: print("The score is ", score) player_choice = input("Choose: Rock, Paper, Scissors: ").lower() if player_choice in valid_inputs: computer_choice = valid_inputs[random.randint(0, 2)] print("The computer chose " + computer_choice + ".") if player_choice == computer_choice: print("Tie! Try again.") else: if computer_choice == "scissors": if player_choice == "rock": print("The computer got you!") score -= 1 else: print("You got the computer!") score += 1 elif computer_choice == "rock": if player_choice == "paper": print("The computer got you!") score -= 1 else: print("You got the computer!") score += 1 elif computer_choice == "paper": if player_choice == "scissors": print("The computer got you!") score -= 1 else: print("You got the computer!") score += 1

    else:
        print("Invalid input, Please try again.")
else:
    print("Game over!")
    if score == 2:
        print("You win!")
    else:
        print("You lose!")
    game = False