Python Forum
why my function doesn't work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why my function doesn't work
#1
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>
Reply
#2
'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)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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)
Reply
#4
(Nov-19-2019, 07:09 PM)gontajones Wrote: 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)

I'd also use this one if I were a beginner, still, I like the option ichabod801 suggested too
Reply
#5
thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PIP doesn't work YKR 1 522 Mar-28-2025, 02:10 PM
Last Post: snippsat
  I'm trying to install python 3.11.11 on windows 10 - it doesn't work Petonique 2 1,552 Feb-04-2025, 05:42 PM
Last Post: snippsat
  Extending list doesn't work as expected mmhmjanssen 2 1,312 May-09-2024, 05:39 PM
Last Post: Pedroski55
  print doesnt work in a function ony 2 1,037 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,873 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 3,415 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 1,776 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  I dont know why my function won't work? MehHz2526 3 1,988 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 2,547 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 6,618 May-30-2022, 03:31 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020