Help! Stuck with "LearnPythonTheHardWay2ndEdition"

This is the place for queries that don't fit in any of the other categories.

Help! Stuck with "LearnPythonTheHardWay2ndEdition"

Postby Vergolinx » Fri May 03, 2013 9:00 am

Hello, it is a nice book that I clung to from the moment I started it.
However, i think i have struck on a problem that may have nothing to do with any typo or something, but rather something more technical.
The problem, if any of you is familiar with this e-book, is that in exercise 19, when i run the script in command prompt, i get this strange error:

Code: Select all
Traceback (most recent call last):
  File "ex19.py", line 17, in <module>
    cheese_and_crackers(10+20, 5+6)
TypeError: 'tuple' object is not callable


Let's say I will give this variable one value with the equals sign, I get the next error:

Code: Select all
Traceback (most recent call last):
  File "ex19.py", line 20, in <module>
    cheese_and_crackers(amount_of_cheese+100, amount_of_crackers+1000)
TypeError: 'int' object is not callable


What could be the reason for this?


Thank you for your time!
Oliver
Vergolinx
 
Posts: 3
Joined: Fri May 03, 2013 8:46 am

Re: Help! Stuck with "LearnPythonTheHardWay2ndEdition"

Postby stranac » Fri May 03, 2013 10:49 am

cheese_and_crackers should be a function.
My guess would be that you're assigning it something else somewhere in your code.

But you need to show the exact code you're trying to run if you want more specific help.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help! Stuck with "LearnPythonTheHardWay2ndEdition"

Postby Vergolinx » Fri May 03, 2013 12:59 pm

stranac wrote:cheese_and_crackers should be a function.
My guess would be that you're assigning it something else somewhere in your code.

But you need to show the exact code you're trying to run if you want more specific help.


Code: Select all
def cheese_and_crackers(cheese_count, boxes_of_crackers):
   print "You have %d cheeses!" % cheese_count
   print "You have %d boxes of crackers!" % boxes_of_crackers
   print "Man that's enough for a party!"
   print "Get a blanekt.\n"
   
print "We can just give the function numbers direcly:"
cheese_and_crackers(20, 30)

print "OR, we can use variables from our script:"
amount_of_cheese=10
amount_of_crackers=50

cheese_and_crackers=(amount_of_cheese, amount_of_crackers)

print "We can even do math inside too:"
cheese_and_crackers(10+20, 5+6)

print "And we can combine two, variables, and math:"
cheese_and_crackers(amount_of_cheese+100, amount_of_crackers+1000)


Here it is, next time i'll know to post.
Vergolinx
 
Posts: 3
Joined: Fri May 03, 2013 8:46 am

Re: Help! Stuck with "LearnPythonTheHardWay2ndEdition"

Postby stranac » Fri May 03, 2013 1:50 pm

This line is the problem:
Code: Select all
cheese_and_crackers=(amount_of_cheese, amount_of_crackers)


You're replacing the cheese_and_crackers() function with a tuple.
I think you meant to call the function instead(you just have an = sign that's not supposed to be there):
Code: Select all
cheese_and_crackers(amount_of_cheese, amount_of_crackers)
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help! Stuck with "LearnPythonTheHardWay2ndEdition"

Postby Vergolinx » Fri May 03, 2013 8:01 pm

stranac wrote:This line is the problem:
Code: Select all
cheese_and_crackers=(amount_of_cheese, amount_of_crackers)


You're replacing the cheese_and_crackers() function with a tuple.
I think you meant to call the function instead(you just have an = sign that's not supposed to be there):
Code: Select all
cheese_and_crackers(amount_of_cheese, amount_of_crackers)


Thank you very much, how silly of me...
Code never lies.
Vergolinx
 
Posts: 3
Joined: Fri May 03, 2013 8:46 am


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], W3C [Linkcheck] and 4 guests