-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
101 lines (77 loc) · 2.4 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import random
# define terminal colours
def prGreen(skk):
print("\033[92m{}\033[00m".format(skk))
def prRed(skk):
print("\033[91m{}\033[00m".format(skk))
def prPurple(skk):
print("\033[95m{}\033[00m".format(skk))
# Print necessary information
prPurple("Welcome to rock paper scissors! For rock, type r, for paper, type p, and for scissors, type s. Best of 3, and goodluck!")
# Setup variables
computer_score = 0
user_score = 0
# bulk of code
def game():
global options
# scoring system
def scores():
global computer_score
global user_score
if user_score == 3:
prGreen("You win!")
exit()
elif computer_score == 3:
prRed("The computer wins!")
exit()
# input validation
def checker():
# make scores global values
global computer_score
global user_score
# setup computer response
options = ["r", "p", "s"]
response = random.choice(options)
# checker logic
if response == user_input:
prPurple("Reroll!")
game()
elif response == "r" and user_input == "p":
prGreen("You get a point!")
user_score = user_score + 1
scores()
game()
elif response == "r" and user_input == "s":
prRed("The computer gets a point!")
computer_score = computer_score + 1
scores()
game()
elif response == "s" and user_input == "r":
prGreen("You get a point!")
user_score = user_score + 1
scores()
game()
elif response == "s" and user_input == "p":
prRed("The computer gets a point!")
computer_score = computer_score + 1
scores()
game()
elif response == "p" and user_input == "r":
prRed("The computer gets a point!")
computer_score = computer_score + 1
scores()
game()
elif response == "p" and user_input == "s":
prGreen("You get a point!")
user_score = user_score + 1
scores()
game()
else:
prRed("Your response is not valid. Please try again.")
game()
# take in user input
user_input = input("What is your input? ")
user_input = user_input.lower()
checker()
# starting the game!
game()