Python Forum
TypeError Decoration Intuition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError Decoration Intuition
#1
The instructor did not completed the code and i tried to run it, I am getting a name error why?
Here is the code:
def calcFormula1(x,y,z):
return x*y+x/2 +2


def calcFormula2(x,y):
return x*x*x +y*y*y +x+y+10

def printOutputReport1(func, x,y,z):
z=func(x,y)
print("----------This is a report for your formula------------")
print("You X variable is:", x)
print("You Y variable is:", y)
print("The result of your formula is ", z)

def printOutputReport2(func, x,y):
z=func(x,y)
print("----------This is a report for your formula------------")
print("You X variable is:", x)
print("You Y variable is:", y)
print("The result of your formula is ", z)


printOutputReport1(calcFormula1, 4 , 2)
printOutputReport2(calcFormula2, 7 , 2)

Here is the result coming out:
TypeError Traceback (most recent call last)
Cell In[20], line 23
19 print("You Y variable is:", y)
20 print("The result of your formula is ", z)
---> 23 printOutputReport1(calcFormula1, 4 , 2)
24 printOutputReport2(calcFormula2, 7 , 2)

TypeError: printOutputReport1() missing 1 required positional argument: 'z'


What is missing in the argument, Asigning value to (z) does not solve the code.
Your input is most appreciated.
Gribouillis write Jul-25-2023, 10:04 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
You are not getting a name error. You are getting a type error. You only pass 3 arguments to a function that expects 4.
Reply


Forum Jump:

User Panel Messages

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