Mathematical Game
Mathematical Game
Lab)
Name: Pranav Sharma
Prn: 21070122116
Class: CSE-B3
Rock Paper Scissors is a hand game, usually played between two people, in
which each player simultaneously forms one of three shapes with an
outstretched hand. These shapes are "rock" (a closed fist), "paper" (a flat
hand), and "scissors" (a fist with the index finger and middle finger
extended, forming a V).
A simultaneous, zero-sum game, it has three possible outcomes: a draw, a
win or a loss.
A player who decides to play rock will beat another player who has chosen
scissors ("rock crushes scissors" or "breaks scissors" or sometimes "blunts
scissors") but will lose to one who has played paper ("paper covers rock");
a play of paper will lose to a play of scissors ("scissors cuts paper"). If both
players choose the same shape, the game is tied and is usually immediately
replayed to break the tie.
CODE IN PYTHON:
import time
import sys import
random def
win(): print('THE
GAME: You win.')
def lost():
print('THE GAME:
You lost.') def
draw():
print('THE GAME:
Its a draw.') def
the_game():
moves = ['rock',
'paper', 'scissors']
print('THE GAME:
Rock, Paper,
Scissors?')
attempts = 3
while True: if
attempts == 0:
print('THE GAME:
You failed to
provide a correct
option to play the
game. Goodbye.')
time.sleep(3)
sys.exit(0) player
=
str(input('Player:
')).lower() if
player.lower() not
in moves:
print(f'THE GAME: Invalid Option! You have {attempts} attempts left.')
attempts -= 1 else:
computer = random.choice(moves)
print(f'Computer: {computer}') if player ==
computer: draw() elif player == 'rock' and
computer == 'scissors':
win() elif player == 'rock' and computer ==
'paper': lost() elif player == 'paper' and
computer == 'rock':
win() elif player == 'paper' and computer ==
'scissors': lost() elif player == 'scissors' and
computer == 'paper':
win() elif player == 'scissors' and computer ==
'rock':
lost() else: pass play_again = str(input('THE
GAME: Retry? (y/n): ')) if play_again.lower() ==
'y':
the_game()
elif play_again.lower() == 'n':
print('THE GAME: Game Over. Goodbye.')
time.sleep(2.5) sys.exit(0) else:
print('THE GAME: Invalid Options. Goodbye.')
time.sleep(2.5)
sys.exit(0) if
__name__=='__main__':
the_game()
OUTPUT: