help with this game
Greg Krohn
greg at invalid.invalid
Sat Jul 17 13:54:41 EDT 2004
Alex Endl wrote:
> 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.
When you need help figuring out an error, be sure to post your exception
traceback.
This is the one I got when I ran your code:
Traceback (most recent call last):
File "...\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "...\greg\My Documents\Projects\Script1.py", line 15, in ?
print "trie number", c ("out of 10")
TypeError: 'int' object is not callable
Now, on to your code:
> 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")
The problem is on this line (and line 20 also, of course). What you most
likely want is:
> print "trie number", c, "(out of 10)"
Note that I added a comma and moved the quotation marks. The syntax
foo(bar) is for calling function named foo with an argument called bar.
Just like randint and input. So Python thought c was your function and
"out of 10" was an argument. But, alas, c in an int, not a function, so
it couldn't call it. That's the error.
> 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
No problem, my time is worthless. ;)
greg
More information about the Python-list
mailing list