Number Guessing Game in Python
Number Guessing Game
Introduction of game:
Very simple game in python which is suitable for beginners of python learner. The user makes a guess and the system tell whether the guess is high or low? and this process continues until the user makes it right under the given chances. There are basically two level of game, Hard and Easy: in the hard level user will get 5 chances and on the Easy level user will have 10 chances.
First
#Create main.py file and paste 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)
#Create art.py and paste the following code
logo = """
)
( /( )
)\()) ( ) ( /( ( ( ( ( ( ( ( ( ) ) (
((_)\ ))\ ( )\()) ))\ )( )\))( ))\ ))\ ( ( )\))( ( /( ( ))\
_((_) /((_) )\ '((_)\ /((_)(()\ ((_))\ /((_) /((_))\ )\ ((_))\ )(_)) )\ ' /((_)
| \| |(_))( _((_)) | |(_)(_)) ((_) (()(_)(_))( (_)) ((_)((_) (()(_)((_)_ _((_)) (_))
| .` || || || ' \()| '_ \/ -_) | '_| / _` | | || |/ -_)(_-<(_-< / _` | / _` || ' \()/ -_)
|_|\_| \_,_||_|_|_| |_.__/\___| |_| \__, | \_,_|\___|/__//__/ \__, | \__,_||_|_|_| \___|
|___/ |___/
"""
# There you go
Comments
Post a Comment