DEV Community

SHAMEEM ALI
SHAMEEM ALI

Posted on

3 1

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()

`

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more