mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-31 05:33:44 +00:00
Merge pull request #180 from Khushi260/master
Guess_the-Number in Python was added
This commit is contained in:
commit
219fce9ad4
35
scripts/Guess the number/Guess_the_number.py
Normal file
35
scripts/Guess the number/Guess_the_number.py
Normal 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")
|
8
scripts/Guess the number/Readme.md
Normal file
8
scripts/Guess the number/Readme.md
Normal 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.
|
Loading…
Reference in New Issue
Block a user