diff --git a/scripts/Guess the number/Guess_the_number.py b/scripts/Guess the number/Guess_the_number.py new file mode 100644 index 0000000..7baaa0b --- /dev/null +++ b/scripts/Guess the number/Guess_the_number.py @@ -0,0 +1,35 @@ +import random + +top_of_range = input("Type a number: ") + +if top_of_range.isdigit(): + top_of_range = int(top_of_range) + + if top_of_range <= 0: + print('Please type a number larger than 0 next time.') + quit() +else: + print('Please type a number next time.') + quit() + +random_number = random.randint(0, top_of_range) +guesses = 0 + +while True: + guesses += 1 + user_guess = input("Make a guess: ") + if user_guess.isdigit(): + user_guess = int(user_guess) + else: + print('Please type a number next time.') + continue + + if user_guess == random_number: + print("You got it!") + break + elif user_guess > random_number: + print("You were above the number!") + else: + print("You were below the number!") + +print("You got it in", guesses, "guesses") diff --git a/scripts/Guess the number/Readme.md b/scripts/Guess the number/Readme.md new file mode 100644 index 0000000..2882791 --- /dev/null +++ b/scripts/Guess the number/Readme.md @@ -0,0 +1,8 @@ +# Guess the number + + + +1. In this game, the [program generates random numbber]but this number is not visible to the player.
+2. Player tries to guess the number. If the player enters the same number that is generated by system then program displays the winning message and game ends there.
+3. If the player enters wrong number then that number is evaluated. If the number is greater than right answer than system gives a hint that entered number is ‘high’ otherwise if number is smaller than right answer than it says ‘lower’.
+4. There are limited number of attempts available with the user to win the game.