Merge pull request #180 from Khushi260/master

Guess_the-Number in Python was added
This commit is contained in:
Bartick Maiti 2022-10-09 02:08:44 +05:30 committed by GitHub
commit 219fce9ad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -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")

View File

@ -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.<br>
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.<br>
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.<br>
4. There are limited number of attempts available with the user to win the game.