Creating a Guessing Game With Python

Guess Game

Guess Game

As a beginner I wanted to get the hold off the basic concepts of python by making some playful apps. So this is one of those programs…

Guess Game

As a beginner I wanted to get the hold off the basic concepts of python by making some playful apps. So this is one of those programs which will help the beginners to learn some basic concepts and how they are implemented.


import random
secret=random.randint(1,20)
#random module is useful for getting a random number which the user has to guess.
#randint function of the random module gets a random number between 1-20 and stores it in a variable named "secret". You can increase or decrease the range according to your need.

print("you have to guess the secret number between 1-20")
print("Let's begin!!!")
for chances in range(1,5):
print("Take a guess")
guess=int(input())
if guess> secret:
print("your guess is high")
print("sorry")
elif guess<secret:
print("your guess is low")
print("sorry")
else:
break
if guess== secret:
print("your guess is correct, Congratulations!!!!")
print("number of attempts taken"+ str(chances)+ 'guesses!')
else:
print("Nope!!!! The number is was thinking of was "+ str(secret))

#I have given user 4 chances to make a correct guess by running the for loop from range 1-5.
#If within those chances user makes a correct guess the loops comes out with the congratulations statement else if the chances exceeds the number of guess else part of the program is executed.

I know this is fairly simple program to write but for beginners just venturing out in the python world this will be a great starting point and on successfully executing this program will be give you inner joy which i myself felt in the starting phase.

Thank You.

Comments

Popular Posts