[Tutor] Problems ugh help please
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat Oct 13 22:41:06 CEST 2012
On 13/10/2012 21:17, Amanda Colley wrote:
> I am trying to add the total pounds that will be shipped. I keep getting an
> error of unknown format code 'f' for object of type 'str' when I try to
> float the pounds. and when I dont float it it gives me a total weight of
> <function pounds at 0x00000000032B92CB> when it exicutes. here is the code
> I have.
>
> 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
> 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)
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
It helps if you show all of your code and the complete traceback.
Having said that look carefully at your code. You've a function called
pounds that's trying to print something called pounds and return pounds.
The pounds function calls the weight function which sets something
called pounds but does nothing with it. Within the pounds function you
set h_book and p_book to None as this will be the default returned by
weight as you haven't specified a return statement within weight. That
doesn't matter as you don't use h_book and p_book anyway, at least not
in the code that you've shown. Got it?
I'll leave you to sort out your code. If you still have problems please
come back and ask, my barks's much worse than my bite :)
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list