-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissors_version_2.py
61 lines (51 loc) · 1.97 KB
/
rock_paper_scissors_version_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
# Project: Rock, Paper, Scissors Game
# Description: This is version 2 which I updated from version 1 when I did updated my programming skills.
A simple Python game where the user plays against the computer. The user chooses between rock, paper,
and scissors, and the computer randomly selects one. The program then determines the winner based on the rules of
the game.
# Level: Intermediate
Author: Pranjal Sarnaik
Date: 2024-11-30
"""
# Importing random module to generate random integer number
import random
from art import rock, paper, scissors, logo
from game_rules import rules
game_images = [rock, paper, scissors]
while True:
print(logo)
print(rules)
print("Welcome to Rock, Paper and Scissors game: Type 0 for Rock, 1 for Paper and 2 for Scissors")
# Asking uer to choose between 0, 1, 2.
while True:
try:
user_choice = int(input("Please enter your choice (0, 1, 2): "))
if user_choice in [0, 1, 2]:
break
else:
print("Please enter valid input: (0, 1, 2)")
except ValueError:
print("Please enter valid input: (0, 1, 2)")
if 2 >= user_choice >= 0:
print(game_images[user_choice])
# Computer choosing random number using random module
computer_choice = random.randint(0,2)
print(f"Computer choose:\n{game_images[computer_choice]}")
# Checking the conditions for win and loose by comparing choice of user and computer
if user_choice == computer_choice:
print("It is draw")
elif (user_choice == 0 and computer_choice == 2) or \
(user_choice == 1 and computer_choice == 0) or \
(user_choice == 2 and computer_choice == 1):
print("You Win!")
else:
print("You Loose")
want_to_play = input("Do you want to play again, type 'Y' and 'N': ").upper()
if want_to_play == "Y":
print("\n" * 25)
pass
else:
print("See you soon! Stay awesome!!")
break
# End of the game