DEV Community

SHAMEEM ALI
SHAMEEM ALI

Posted on

A Guess Game

`#Number Guessing Game Objectives:
from random import randint
EASY_LEVEL = 10
HARD_LEVEL = 5
def difficulty():
if input("Choose difficultty type 'easy'or 'hard'")=="easy":
return EASY_LEVEL
else:
return HARD_LEVEL

def checking_ans(guess,answer,turning_point):
if guess > answer:
print("Too high")
return turning_point - 1
elif guess < answer :
print("Too low")
return turning_point -1
else:
return f"You answered {answer}"

Include an ASCII art logo.

Allow the player to submit a guess for a number between 1 and 100.

Check user's guess against actual answer. Print "Too high." or "Too low." depending on the user's answer.

If they got the answer correct, show the actual answer to the player.

Track the number of turns remaining.

If they run out of turns, provide feedback to the player.

Include two different difficulty levels (e.g., 10 guesses in easy mode, only 5 guesses in hard mode).

def game():
print("WELCOME GUESSING GAME")
print("I am thinking of a number between 1 to ")
answer = randint(1,100)
turning_point = difficulty()
print(f"You have {turning_point} attemtts")
guess = 0
while guess != answer:
guessing = int(input("Make a guess :"))
turning_point = checking_ans(guess,answer,turning_point)
if turning_point == 0 :
return "you are tired , chances compled"
elif guess != answer:
return "Make guess...."

game()

`

Top comments (0)