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>
'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)
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)
(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