-
Notifications
You must be signed in to change notification settings - Fork 5
/
rockpaper.py
75 lines (68 loc) · 2.96 KB
/
rockpaper.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# importing required modules
import random as ran #random module is to select random option for the computer
import time #time module is used to get the current time to generate random seed value
items = ["rock","paper","pencil","siccors"] #items tuple contains the options
com_point , usr_point = 0 ,0 #initial score of both user and computer
print("\nWelcome to the game of introverts ")
print("\nLets play rock.. paper .. siccors with computer cuz you have no frnds")
print("\nRules: ")
print("\nYou must type the option with correct spelling otherwise computer gets a point ")
print("\nThe options are : ")
for i in items: #Printing all the options so that the user can check the available option
print(i)
print("\nTo stop the game you can press ctrl + c")
try: #to catch the ctrl + c key interruption so that we can end the game; see the except block at line63
while True: #To continuerun the game
ran.seed(time.time()) #setting the seed value of the random module
com = ran.choice(items) #setting the option of the computer fisrt so that he cant cheat by looking into the memory block which saves our option
option = input("Enter your choice : ")
option = option.lower()
try:
print("The computer chose : ",com)
if option in items: #checking to see that the user have entered a valid option , check the else block at line 56
if com == option :
print("\ndraw")
elif com == "rock":
if option == "paper":
print("\nuser wins")
usr_point += 1
else:
print("\ncomputer wins")
com_point += 1
elif com == "paper":
if option == "siccors" or option == "pencil":
print("\nuser wins")
usr_point += 1
else:
print("\ncomputer wins")
com_point += 1
elif com == "pencil":
if option == "rock" or option == "siccors":
print("\nuser wins")
usr_point += 1
else:
print("\ncomputer wins")
com_point += 1
else: # the final choice that the computer have is to take sicccors
if option =="rock":
print("\nuser wins")
usr_point +=1
else:
print("\ncomputer wins")
com_point += 1
else: #if the user enters a wrong option , he can correc his mistake
print("Wrong option , TRY AGAIN \n\n")
continue
except:
print("\n\nSomething happened ! Please try again !! \n\n")
except KeyboardInterrupt:
print('\n','**' * 16, '\n')
print("\n\nGame Ended ")
print("\nUser Score : " , usr_point)
print("\ncomputer Score : " , com_point)
if usr_point > com_point:
print("\nUser wins")
elif usr_point == com_point:
print("\nDRAW !! ")
else:
print("\ncomputer wins")