Logo 
Search:

Python Articles

Submit Article
Home » Articles » Python » Programming BasicsRSS Feeds

Guess The Number Game in Python

Posted By: Falak Khan     Category: Python     Views: 4913

Code for Guess The Number Game in Python in Python

import random
value=random.randint(1,20)
won=False
wtp=True
while(wtp):
    print"hi ! I m thinking of a no.,can you guess it?"for tri in range(3):
        guess=int(raw_input("Enter a no: "))
        if(guess==value):
            won=True
            print"Congrats"break
        elif(tri<2):
                print"sorry! try again"
                print 3-tri-1,"tries left"if(won==False and tri==2):
            print"sorry ! you lost"
            print "NO. was:", value
    choice=str(raw_input("would you like to play again y/n "))
    if(choice=="n"):
        wtp=False
                         
        
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Guess The Number Game in Python Or get search suggestion and latest updates.

Falak Khan
Falak Khan author of Guess The Number Game in Python is from Pakistan.
 
View All Articles

 

Other Interesting Articles in Python:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Abhishek Singh from India Comment on: May 13
;;;;;;;;;;;;;;;;;;;;;;

View All Comments