Positional Argument Error

Hello! I am new to PyTorch and I am here because I need help! I am learning Python and can’t really find a one-on-one tutor over the summer. Extension activities help. (I’m a teacher, too). I’ve seen the topic I need help with a few times, but I still can’t figure out why I’m still getting the error.

HELP!

The error is throws is for line 79: " Python takes 1 positional argument but 2 were given". However, I included the self argument.

“”"Class-based Leibniz formula for Pi.

Description: This program executes the Pi function by way of classes and also executes the circumference of a circle, the area of a circle, the volume of a circle and the surface area of a circle.

Programmer: Tecia Marshall

“”"

class Pi_LeibnizClass:
“”“A class for use with the Leibniz formula for Pi.”""
def init(self,n):
“”“Calculates the value of Pi.”""
numerator = 4
denominator = 1
self.value_of_pi = 0
counter = 0

    while counter < n:
        nextterm = numerator/denominator * (-1)**counter
        self.value_of_pi += nextterm
        denominator += 2
        counter += 1

def get_circumference(self):
    """Displays calculated value of the circumference of a circle."""
    return (self.value_of_pi) * (self.radius) * 2
    
def get_area(self):
    """Displays calculated value of the area of a circle."""
    return (self.value_of_pi) * (self.radius) ** 2

def get_volume(self):
    """Displays calculated value of the volume of a sphere."""
    return 4 / 3 * (self.value_of_pi) * (self.radius) ** 3

def get_surfacearea (self):
    """Displays calculated value of the surface area of a sphere."""
    return 4 * (self.value_of_pi) * (self.radius) ** 2

def error_message():
“”“This function contains the reusable error message.”""
print(‘You have entered an invalid value. You must enter a positive floating poing value or an integer.’)
main()

def ending():
“”“Allows the user to run the program again or terminate it.”""
print(’’’
Type A to run the program again.
Press Enter to end the program.’’’)
runagain = input()
if runagain == ‘A’:
main()

def main():
“”“This function controls the main thread of the program.”""
print(‘Please enter a floating point value’)
response = input()
try:
max_counter = int(response)
except ValueError:
error_message()
else:
if max_counter <= 0:
error_message()
else:
Leibniz_object = Pi_LeibnizClass(max_counter)
# Collect the number from the user to use for the radius
print ('Please enter your radius number: ')
response = input()
try:
max_counter = float(response)
except ValueError:
print(‘You have entered an invalid value. You must enter a positive floating point value or an integer.’)
print (‘Please restart the program and try again.’)
else:
circumference = Leibniz_object.get_circumference(max_counter)
print (circumference)
area = Leibniz_object.get_area(max_counter)
print (area)
volume = Leibniz_object.get_volume(max_counter)
print (volume)
surface = Leibniz_object.get_surfacearea(max_counter)
print (surface)
ending()

main()

In this line of code:

circumference = Leibniz_object.get_circumference(max_counter)

you are passing an argument to get_circumference, which doesn’t expect any additional arguments:

def get_circumference(self):
    """Displays calculated value of the circumference of a circle."""
    return (self.value_of_pi) * (self.radius) * 2

so you would have to either add this argument to the function definition or don’t pass it to this method.
The same applies to other methods (you are also passing an argument it, while none is expected).

PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier :wink:

Okay, okay. I’m a beginner. So take (max_counter) and add it to each method? (max_counter) is the argument, right?

I removed the (max_counter) argument. I am getting the same error.

It’s working for me once I remove the max_counter argument and add the missing self.radius to the object:

class Pi_LeibnizClass:
    def __init__(self, n):
        numerator = 4
        denominator = 1
        self.value_of_pi = 0
        counter = 0
        self.radius = 1
    
        while counter < n:
            nextterm = numerator/denominator * (-1)**counter
            self.value_of_pi += nextterm
            denominator += 2
            counter += 1

    def get_circumference(self):
        """Displays calculated value of the circumference of a circle."""
        return (self.value_of_pi) * (self.radius) * 2
        
    def get_area(self):
        """Displays calculated value of the area of a circle."""
        return (self.value_of_pi) * (self.radius) ** 2
    
    def get_volume(self):
        """Displays calculated value of the volume of a sphere."""
        return 4 / 3 * (self.value_of_pi) * (self.radius) ** 3
    
    def get_surfacearea (self):
        """Displays calculated value of the surface area of a sphere."""
        return 4 * (self.value_of_pi) * (self.radius) ** 2


def main():
    Leibniz_object = Pi_LeibnizClass(10)
    circumference = Leibniz_object.get_circumference()
    print (circumference)
    area = Leibniz_object.get_area()
    print (area)
    volume = Leibniz_object.get_volume()
    print (volume)
    surface = Leibniz_object.get_surfacearea()
    print (surface)

What is it returning for you? I’m now getting an error of AttributeError: "Pi_LeibnizClass object has no attribute ‘get_circumference’

But circumference is defined.

Wait. I got it to run!!!

Now I have to format to 3 decimal places face palm