Positional Argument Error

Tecia_Marshall: <p>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.</p>
<p><strong>HELP!</strong></p>
<p>The error is throws is for line 79: " Python takes 1 positional argument but 2 were given". However, I included the self argument.</p>
<p>“”"Class-based Leibniz formula for Pi.</p>
<p>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.</p>
<p>Programmer: Tecia Marshall</p>
<p>“”"</p>
<p>class Pi_LeibnizClass:<br>
“”“A class for use with the Leibniz formula for Pi.”""<br>
def <strong>init</strong>(self,n):<br>
“”“Calculates the value of Pi.”""<br>
numerator = 4<br>
denominator = 1<br>
self.value_of_pi = 0<br>
counter = 0</p>
<pre><code>    while counter &lt; 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
</code></pre>
<p>def error_message():<br>
“”“This function contains the reusable error message.”""<br>
print(‘You have entered an invalid value. You must enter a positive floating poing value or an integer.’)<br>
main()</p>
<p>def ending():<br>
“”“Allows the user to run the program again or terminate it.”""<br>
print(’’’<br>
Type A to run the program again.<br>
Press Enter to end the program.’’’)<br>
runagain = input()<br>
if runagain == ‘A’:<br>
main()</p>
<p>def main():<br>
“”“This function controls the main thread of the program.”""<br>
print(‘Please enter a floating point value’)<br>
response = input()<br>
try:<br>
max_counter = int(response)<br>
except ValueError:<br>
error_message()<br>
else:<br>
if max_counter &lt;= 0:<br>
error_message()<br>
else:<br>
Leibniz_object = Pi_LeibnizClass(max_counter)<br>
# Collect the number from the user to use for the radius<br>
print ('Please enter your radius number: ')<br>
response = input()<br>
try:<br>
max_counter = float(response)<br>
except ValueError:<br>
print(‘You have entered an invalid value. You must enter a positive floating point value or an integer.’)<br>
print (‘Please restart the program and try again.’)<br>
else:<br>
circumference = Leibniz_object.get_circumference(max_counter)<br>
print (circumference)<br>
area = Leibniz_object.get_area(max_counter)<br>
print (area)<br>
volume = Leibniz_object.get_volume(max_counter)<br>
print (volume)<br>
surface = Leibniz_object.get_surfacearea(max_counter)<br>
print (surface)<br>
ending()</p>
<p>main()</p>

ptrblck: <p>In this line of code:</p>
<pre><code class="lang-python">circumference = Leibniz_object.get_circumference(max_counter)
</code></pre>
<p>you are passing an argument to <code>get_circumference</code>, which doesn’t expect any additional arguments:</p>
<pre><code class="lang-python">def get_circumference(self):
    """Displays calculated value of the circumference of a circle."""
    return (self.value_of_pi) * (self.radius) * 2
</code></pre>
<p>so you would have to either add this argument to the function definition or don’t pass it to this method.<br>
The same applies to other methods (you are also passing an argument it, while none is expected).</p>
<p>PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

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

Tecia_Marshall: <p>I removed the (max_counter) argument. I am getting the same error.</p>

ptrblck: <p>It’s working for me once I remove the <code>max_counter</code> argument and add the missing <code>self.radius</code> to the object:</p>
<pre><code class="lang-python">class Pi_LeibnizClass:
    def __init__(self, n):
        numerator = 4
        denominator = 1
        self.value_of_pi = 0
        counter = 0
        self.radius = 1
    
        while counter &lt; 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)
</code></pre>

Tecia_Marshall: <p>What is it returning for you? I’m now getting an error of AttributeError: "Pi_LeibnizClass object has no attribute ‘get_circumference’</p>
<p>But circumference is defined.</p>

Tecia_Marshall: <p>Wait. I got it to run!!!</p>

Tecia_Marshall: <p>Now I have to format to 3 decimal places <em>face palm</em></p>