Compare commits
No commits in common. "ebb13f83e34b693ada28257756238e8500b58256" and "598d49935629e27f9575e9c8df11ec9175c6a0a5" have entirely different histories.
ebb13f83e3
...
598d499356
|
@ -1322,69 +1322,6 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
|
||||||
|
|
||||||
<summary> The Object Oriented program of Guess The Number </summary>
|
|
||||||
|
|
||||||
```python
|
|
||||||
import random
|
|
||||||
|
|
||||||
class ChoiceNumberInTheRange(object):
|
|
||||||
def ReturnRandomNumber(self, range):
|
|
||||||
return random.randint(0,int(range))
|
|
||||||
|
|
||||||
class GetTheNumberOfPlayer(object):
|
|
||||||
def GetNumber(self):
|
|
||||||
try:
|
|
||||||
Number = int(input("What is the number in your mind ?"))
|
|
||||||
return Number
|
|
||||||
except:
|
|
||||||
print("I need number !!")
|
|
||||||
|
|
||||||
class Right(object):
|
|
||||||
|
|
||||||
def Verification(self, right_number, number_guessed):
|
|
||||||
if right_number == number_guessed:
|
|
||||||
SayCorrect()
|
|
||||||
exit()
|
|
||||||
else:
|
|
||||||
NotCorrect(right_number, number_guessed)
|
|
||||||
|
|
||||||
|
|
||||||
class NotCorrect(object):
|
|
||||||
def __init__(self, right_number, number_guessed):
|
|
||||||
if right_number < number_guessed:
|
|
||||||
SayBigger()
|
|
||||||
elif right_number > number_guessed :
|
|
||||||
SaySmaller()
|
|
||||||
|
|
||||||
class SayBigger(object):
|
|
||||||
def __init__(self):
|
|
||||||
print("Your number is bigger")
|
|
||||||
|
|
||||||
class SaySmaller(object):
|
|
||||||
def __init__(self):
|
|
||||||
print("Your number is smaller")
|
|
||||||
|
|
||||||
class SayCorrect(object):
|
|
||||||
def __init__(self):
|
|
||||||
print("You win")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
Range = input("What is the range do you want")
|
|
||||||
RandomValue = ChoiceNumberInTheRange().ReturnRandomNumber(Range)
|
|
||||||
while True:
|
|
||||||
TheGuestResponse = GetTheNumberOfPlayer().GetNumber()
|
|
||||||
Right().Verification(right_number= RandomValue, number_guessed= TheGuestResponse)
|
|
||||||
|
|
||||||
```
|
|
||||||
All classes have a different task.
|
|
||||||
As you can see, there are classes for getting a random value in a range value (_ChoiceNumberInTheRange_ class).
|
|
||||||
Class for checking if the number is right or not (_Right_ class).
|
|
||||||
Classes for talking with the player if he wins or not.
|
|
||||||
If player getting the right value, you can use exit() method to stop the program.
|
|
||||||
</details>
|
|
||||||
|
|
||||||
🏃 Try it
|
🏃 Try it
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue