×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Guess the Number Python Project

## Guess the Number Python Project

(OP)
Hello, I am working on a Guess the Number Python Project and I want to know if the provided sample code is correct or not. I have taken this source code on TechGeekBuzz and in this python project, I want to generate a random number and the user will have only 3 chances to guess. and after the user each attempt, the user will get a Popup message about how the user is close to the answer, if the user completed all the chances, the system will display the correct answer. Can anyone tell me, if Is it right or provide some other source code for the number-guessing project?

#### CODE --> Python

import random #bring in the random number
import time
number=random.randint(1, 200) #pick the number between 1 and 200

def intro():
print(name + ", we are going to play a game. I am thinking of a number between 1 and 200")
time.sleep(.5)

def pick():
guessesTaken = 0
while guessesTaken < 6: #if the number of guesses is less than 6
time.sleep(.25)
enter=input("Guess: ") #inserts the place to enter guess
try: #check if a number was entered
guess = int(enter) #stores the guess as an integer instead of a string

if guess<=200 and guess>=1: #if they are in range
guessesTaken=guessesTaken+1 #adds one guess each time the player is wrong
if guessesTaken<6:
if guess<number:
print("The guess of the number that you have entered is too low")
if guess>number:
print("The guess of the number that you have entered is too high")
if guess != number:
time.sleep(.5)
print("Try Again!")
if guess==number:
break #if the guess is right, then we are going to jump out of the while block
if guess>200 or guess<1: #if they aren't in the range
print("Silly Goose! That number isn't in the range!")
time.sleep(.25)
print("Please enter a number between 1 and 200")

except: #if a number wasn't entered
print("I don't think that "+enter+" is a number. Sorry")

if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + name + '! You guessed my number in ' + guessesTaken + ' guesses!')

if guess != number:
print('Nope. The number I was thinking of was ' + str(number))

playagain="yes"
while playagain=="yes" or playagain=="y" or playagain=="Yes":
intro()
pick()
print("Do you want to play again?")
playagain=input() 

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!