Look at line 11 of costAd(). You called it in your module without an argument.
txwooley
Junior Poster in Training
84 posts since Apr 2009
Reputation Points: 10
Solved Threads: 7
sorry im new to this, how was i supposed to call it? Can you give me some examples please? Thanks. :)
I don't think you need to call it in the module. I'm not too familiar with homemade modules, but just the definition should be enough. Try commenting out line 11 in the module and run it again.
txwooley
Junior Poster in Training
84 posts since Apr 2009
Reputation Points: 10
Solved Threads: 7
This will allow you to test your module ...
# Function that recieves number of characters and calculate cost
# of advertising, save module as costAd.py (case sensitive)
def costAd(numChar):
if numChar >= 15:
cost = 35.00
else:
cost = 35.00 + ((numChar - 15) * 3.55)
return cost
# test module costAd
# this will be ignored if imported as a module
if __name__ == '__main__':
print costAd(20)
print costAd(10)
Your main program is okay.
Also notice that 4 spaces is the customary indentation, don't use tabs.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
costAd() <-- dead code after the return statement :)
No you dont give function an argument. def costAd(numChar):
Then you most always pass an argument when calling the function.
Your error message is pretty clear.TypeError: costAd() takes exactly 1 argument (0 given)
Look at vega code. costAd(20)
If we give a default value as argument we can call like this or with an argument
def costAd(numChar=0):
if numChar >= 15:
cost = 35.00
else:
cost = 35.00 + ((numChar - 15) * 3.55)
return cost
print costAd()
print costAd(20)
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294