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
  print doesnt work in a function ony 2 233 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 870 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,681 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 842 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  I dont know why my function won't work? MehHz2526 3 1,150 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 1,655 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 4,054 May-30-2022, 03:31 PM
Last Post: bowlofred
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 1,930 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,660 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  Process doesn't work but Thread work ! mr_byte31 4 2,556 Oct-18-2021, 06:29 PM
Last Post: mr_byte31

Forum Jump:

User Panel Messages

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