Skip to content

Commit

Permalink
Merge pull request #95 from LudovicoSforza/main
Browse files Browse the repository at this point in the history
added guess a number
  • Loading branch information
Rajspeaks authored Oct 28, 2021
2 parents ecdbb4b + 66ce557 commit d7b20c0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Contributors-2021.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,14 @@ LinekdIn profile url: https://linkedin.com/in/aravindha1234u
Twitter profile url: https://twitter.com/aravindha1234u

Country: India
Bio: Student

*Name: Ludovico Piero
*Github username: LudovicoSforza
How many pull requests have you done here: 1

LinekdIn profile url: (write N/A if you don't have)
Twitter profile url: https://twitter.com/Ludovico1337

Country: Australia
Bio: Student
40 changes: 40 additions & 0 deletions Ludovico Piero/guess_a_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import random


class NumberGuessingGame:

def __init__(self):
# define the range
self.LOWER = 1
self.HIGHER = 100

# method to generate the random number
def get_random_number(self):
return random.randint(self.LOWER, self.HIGHER)

# game start method
def start(self):
# generating the random number
random_number = self.get_random_number()

print(
f"Guess the randomly generated number from {self.LOWER} to {self.HIGHER}")

# heart of the game
chances = 0
while True:
user_number = int(input("Enter the guessed number: "))
if user_number == random_number:
print(
f"-> Hurray! You got it in {chances + 1} step{'s' if chances > 1 else ''}!")
break
elif user_number < random_number:
print("-> Your number is less than the random number")
else:
print("-> Your number is greater than the random number")
chances += 1


# instantiating and starting the game
numberGuessingGame = NumberGuessingGame()
numberGuessingGame.start()

0 comments on commit d7b20c0

Please sign in to comment.