Number guessing game with Python

Create art.py file and import the following code:


logo = """

)
( /( )
)\()) ( ) ( /( ( ( ( ( ( ( ( ( ) ) (
((_)\ ))\ ( )\()) ))\ )( )\))( ))\ ))\ ( ( )\))( ( /( ( ))\
_((_) /((_) )\ '((_)\ /((_)(()\ ((_))\ /((_) /((_))\ )\ ((_))\ )(_)) )\ ' /((_)
| \| |(_))( _((_)) | |(_)(_)) ((_) (()(_)(_))( (_)) ((_)((_) (()(_)((_)_ _((_)) (_))
| .` || || || ' \()| '_ \/ -_) | '_| / _` | | || |/ -_)(_-<(_-< / _` | / _` || ' \()/ -_)
|_|\_| \_,_||_|_|_| |_.__/\___| |_| \__, | \_,_|\___|/__//__/ \__, | \__,_||_|_|_| \___|
|___/ |___/

"""




Create main.py and import the following code



from art import logo

from random import random
import math

print(logo)
print("Welcome to the Number Guess Game!")
print("I think of a number between 1 and 100")

HARD_LEVEL_CHANCE = 5
EASY_LEVEL_CHANCE = 10

difficulty_level = input("Choose level, 'hard' or 'easy':\n").lower()
answer = math.ceil(random()*100)

end = False

def check_answer(guess, answer, count):
print(f"{level - count} times remaning")
if guess > answer:
return "Too high"
elif guess < answer:
return "Too low"
elif guess == answer:
return False

if difficulty_level == "easy":
level = EASY_LEVEL_CHANCE
else:
level = HARD_LEVEL_CHANCE

count = 0
while not end:
if count >= level:
print("Game over")
end = True
if count < level:
guess = int(input("Make a guess: \n"))
count +=1
ans = check_answer(guess, answer, count)
if ans == False:
end = True
print("You've got it")
else:
print(ans)



Comments

Popular posts from this blog

Where Does Intelligence Begin?

Random is not actually indeterministic, its hard to calculate.

Existence Game