Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8200307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:24:03+00:00 2026-06-07T06:24:03+00:00

I tried to make a simple guess game, but all it does is asks

  • 0

I tried to make a simple “guess game”, but all it does is asks for an input and that’s it.

Here is my code:

import random

def guess():
    if a == b:
        print "Correct!"
        n = input("Press 0 to quit or 1 to try again.")
        if n == 0:
            print ""
        if n == 1:
            return guess
    else:
        print "Wrong! "
        n = input("Press 0 to quit or 1 to try again.")
        if n == 0:
            print ""
        if n == 1:
            return guess

a = random.randint(1,2000)
b = input("Guess a number between 1 and 2000 ")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:24:06+00:00Added an answer on June 7, 2026 at 6:24 am

    You are not calling the guess function. You should add at the end:

    guess(a, b)
    

    and you should modify the guess function as follows:

    def guess(a, b):
        # your code here
    

    This is necessary because you need to pass the values a and b to your guess function. Otherwise, a and b inside the guess function have no value (they are just undefined local variables) and Python would not know what to do.

    By doing the above, you can at least check if you guessed correctly or not. But you’ll need to modify the code a bit more if you want to repeat the guessing.


    As an example, here is an updated version of the guess game that does work:

    import random
    
    def guess(a):
        b = raw_input("Guess a number between 1 and 2000 ")
        if a == b:
            print "Correct!"
        else:
            print "Wrong! "
            n = raw_input("Press 0 to quit or 1 to try again.")
            if n == "0":
                print ""
            if n == "1":
                guess(a)
    
    a = random.randint(1, 2000)
    guess(a)
    

    The function guess now takes one integer: the integer that needs to be guessed. Inside the function, we ask the user for an integer and we store it in b. We then tell the user whether the guess is correct or not. If the guess is correct then the function guess just ends.

    If the guess was wrong then we give the user to chance to try again if they want to. Note that we are now checking if n == "0": instead of if n == 0: because n is a string, not an integer. If the user typed 1 then we call guess again with the integer to be guessed (a) and the whole thing starts again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a simple guess my number game in c++ but
I tried to make a simple contact form via HTML and PHP but the
I'd like to make a subclass of NSInputStream. Simply, I tried to code just
I tried to make an asynchronous UDP client using boost::asio I get some code
I tried to make a click counter in MySQL, but it dose not seem
I tried to make my textbox type in currency format. I did it, but
I tried to make a new bare git repository but I get this error:
I have a simple word jumble game. I made the jumble already, but now
I tried this: #!/usr/bin/python from wsgiref.simple_server import make_server from cgi import parse_qs, escape import
Tried to make a little old school ajax (iframe-javascript) script. A bit of mootools

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.