help with this game

Sean Ross sross at connectmail.carleton.ca
Sat Jul 17 13:22:14 EDT 2004


Hi.

Here is the error your code produces on my machine:

Traceback (most recent call last):
  File
"C:\Python23\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\My Documents\Sean\hacks\guessthenumber.py", line 15, in ?
    print "trie number", c ("out of 10")
TypeError: 'int' object is not callable


The last line of the error message is saying that you are trying to make a
method or function call using an int, and that an int is not callable

        c ("out of 10")    <-- this is function/method call notation

The problem is you've misplaced your quotation marks in

        print "trie number", c ("out of 10")

it should be

        print "trie number", c, "(out of 10)"

Or, if you want to correct the spelling:

        print "try number", c, "(out of 10)"

Changing the two occurrences of that line in your code, will solve that
problem. There are other problems with your code, though.

You only want to give players 10 chances to guess the number - but, the code
you have at the moment won't accomplish that. If the player keeps guessing
incorrectly, then, on the tenth turn, they'll see

to many guesses                                <-- should be "too many
guesses"
try number 10 (out of 10)

and then they'll be allowed to continue guessing forever, or until they
guess the number. Can you see why? The solution is straightforward, so I'll
leave that alone so that you can learn how to solve the problem.

There are two other things I'd like to point out for you:

1.  You say the following twice in the same loop (see if you can figure out
how to say it only once):

        if c == 10:
                    print "to many guesses"
        print "trie number", c ("out of 10")     <-- remember to fix this
bug first though

2. Try changing 'a', 'b', and 'c' to something more meaningful, say

-  'number', or 'theNumber', or 'theNumberToGuess' instead of 'a'
-  'guess', or 'theGuess', or 'playersGuess', or 'theNumberGuessed' instead
of 'b'
-  'tries', or 'numberOfTries' instead of 'c'


Oh, and

    a = random.randint(1, 100)

should be

    a = random.randint(1, 101)

if you want people to guess a number between 1 and 100, inclusive.

Hope that helps,
Sean


"Alex Endl" <alexendl at hotmail.com> wrote in message
news:10fijmnf86rkr20 at corp.supernews.com...
> ok now that i know the random function, i made this guessing game.  I get
an
> error though, and Im new so im not to good at figuring out what its
talking
> about.
>
>
> import random
> a = random.randint(1, 100)
> b=-100
> c=0
> print "Welcome to guess the number"
> print "to play type in a number between 1 and 100."
> print "but you only get ten tries"
> while a != b:
>     c = c + 1
>     b = input ("enter guess:")
>     if b < a :
>         print "to low"
>         if c == 10:
>             print "to many guesses"
>         print "trie number", c ("out of 10")
>     elif b > a :
>         print ("to high")
>         if c == 10:
>             print "to many guesses"
>         print "trie number", c ("out of 10")
> print "you got it in ",c," tries"
>
>
> thanks for your time
>
>





More information about the Python-list mailing list