-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessTheNumberOOP.py
More file actions
43 lines (27 loc) · 973 Bytes
/
guessTheNumberOOP.py
File metadata and controls
43 lines (27 loc) · 973 Bytes
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
#python3
import random
#randNum = 0
class Random:
def __init__(self, min, max):
self.min = min
self.max = max
self.randNum = randNum = 0
self.isGuessing = isGuessing = True
self.playerValue = playerValue = 0
def getRandomNumber(self): # getting a random number itself
self.randNum = random.randint(self.min, self.max)
def guessPlay(self): # actual game-code
print("Guess the number between ", self.min, " and ", self.max, " : ")
self.playerValue = int(input(""))
if self.playerValue < self.randNum:
print("\nToo low... Try again\n")
elif self.playerValue > self.randNum:
print("\nToo high... Try again\n")
else:
self.isGuessing = False
print("\nCongrats! You Won!\n")
r = Random(1, 10) # creating instance of class
# playing game
r.getRandomNumber()
while r.isGuessing:
r.guessPlay()