Reputation: 1
Im new to coding and im trying to learn python on coursera and im having issues with this one exercise
Exercise:
Write a function def areatriangle(b, h):
to compute the area
of a triangle: formula is area = .5 * b * h
.
Output should look like:
The area of a triangle of base 3 and height 5 is 7.5
You can test your function by executing the following code:
#%%
# The following will test areatriangle()
areatriangle(3,5)
areatriangle(2,20)
#%%
But whenever i try to run them in the console i get the error message
TypeError: areatriangle() takes 0 positional arguments but 2 were given
what should i do
Upvotes: 0
Views: 1329
Reputation: 470
TypeError: areatriangle() takes 0 positional arguments but 2 were given
This tells us that the areatriangle() method takes no input parameters.
areatriangle(3,5)
You have given two arguments (breadth and height). Now Python has no idea what to do with them and raises an error.
You can use this:
def areatriangle(breadth, height):
area = .5 * breadth * height
return area # or you can do: return f"The area of a triangle of base {breadth} and height {height} is {area}"
area = areatriangle(3, 5)
print(area)
Upvotes: 1