![]() |
why my function doesn't work - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: why my function doesn't work (/thread-22608.html) |
why my function doesn't work - cimerio - Nov-19-2019 Hi, I am a beginner. I need help. Why the code below doesn't return nothing? def tax(year, value): if year > 2004: tax = value * 22 / 100 else: tax = valor * 11 / 100 tax(2005, 100) print (tax)shows the error (or warning): <function tax at 0x00000000030F47B8> RE: why my function doesn't work - ichabod801 - Nov-19-2019 'tax' is the function itself, not the result of calling the function. What it is printing is not an error or warning, it is the repr of the function. To print the result, either print it directly ( print(tax(2005, 100)) ), or store it in a variable and print the variable:owed = tax(2005, 100) print(owed) RE: why my function doesn't work - gontajones - Nov-19-2019 Maybe this way will be more easy to understand: def get_tax(year, value): if year > 2004: tax = value * 22 / 100 else: tax = value * 11 / 100 return tax tax = get_tax(2005, 100) print(tax) RE: why my function doesn't work - ChislaineWijdeven - Nov-20-2019 (Nov-19-2019, 07:09 PM)gontajones Wrote: Maybe this way will be more easy to understand: I'd also use this one if I were a beginner, still, I like the option ichabod801 suggested too RE: why my function doesn't work - cimerio - Jan-20-2020 thank you |