Thursday, October 6, 2016

A GUESS GAME WITH PYTHON

Hey friends ! I gonna give a source code in python for a guess game...the game is simple the computer thinks of a number between 1 and 50 and gives you six chances to guess it right and it gives u clue by telling if your guess was greater or lesser than the number with computer!hope you like it..


SOURCE
=======
import random       
import os
num=random.randint(1,50)
os.system('cls')
print '\tHOW TO'
print '\t','-'*6
print '\tIn this game I will think of a number from 1 to 50'
print '\tYOU HAVE SIX CHANCES TO GUESS THE NUMBER!'
print ''
print '\tGAME'
print '\t','-'*4
c=1
while c<=6:
    print '\tEnter your guess ',c,':'
    n=int(raw_input())
    if n>num:
        print '\tYour Guess is greater!'
    if n<num:
        print '\tYour Guess is smaller!'
    if n==num:
        break
    c=c+1
if n==num:
    print '\twow you have guessed it right! I thought of ',num
else:
    print '\tYou have finished all your six chances!'


#####################################################################
If you have any doubt ,contact me
run on python 2.7.12 interpreter
save as something.py
This is based on python 2.7 so,it will show error if you run it on python 3.5 interpreter..

OUTPUT
=======
================== RESTART: C:/Python27/guess.py ==================
HOW TO
------------
In this game I will think of a number from 1 to 50
YOU HAVE SIX CHANCES TO GUESS THE NUMBER!

GAME
---------
Enter your guess  1 :
25
Your Guess is smaller!
Enter your guess  2 :
40
Your Guess is greater!
Enter your guess  3 :
35
Your Guess is greater!
Enter your guess  4 :
30
Your Guess is greater!
Enter your guess  5 :
27
wow you have guessed it right! I thought of  27
#####################################################################
FEEL FREE TO ASK ME YOUR DOUBTS AND LEAVE COMMENTS!
#####################################################################

No comments:

Post a Comment