[Tutor] Problems ugh help please

Alan Gauld alan.gauld at btinternet.com
Sun Oct 14 01:10:54 CEST 2012


On 13/10/12 21:17, Amanda Colley wrote:
> I am trying to add the total pounds that will be shipped. I keep getting
> an error

Show us the full error text do not summarize. We lose a lot of 
information that way and have to workj much harder to guess/figure
out what is going wrong.

> def pounds():
>      h_book=weight('Hardback',2.1)
>      p_book=weight('Paperback',1.3)
>      print('Your total weight of book(s) at',pounds)
>      return pounds

Your function is called pounds, and you are printing pounds so you are 
printing your function. You also return your function from your 
function. Also you assign he return value of weight to two variables 
which you don't use for anything.

All of that is decidedly odd and almost certainly wrong.

> def weight(desc,weight):
>      print('How many',desc,'books do you want at',weight,'pounds do you
> want?')
>      num=int(input())
>      pounds=float(num*weight)

And here you have a function called weight that takes a parameter called 
weight. Then you print weight - which one should Python print? The 
function or the parameter? As a rule do not use function names as 
parameter or variable names. Python isn't very good at guessing games.

Also you expect a return from  weight in the pounds() function but you 
don't actually provide any return value in weight, so the default return 
value will be used which is: None.

So before doing anything else think up some new names and try again and 
if you still have problems (and I suspect you will) come back to us
(with the full error text!)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list