mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-30 13:13:47 +00:00
Add files via upload
This commit is contained in:
parent
5d4309d62f
commit
47e9ca72c8
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")
|
Loading…
Reference in New Issue
Block a user