Home How to run a class function
Reply: 0

How to run a class function

user1366
1#
user1366 Published in August 15, 2018, 8:44 pm

I was trying to write some code that would take in the number of sides of a polygon and a user can just randomly input the length of each side

I wanted to make a separate class polygon and the following was my code:

#numSides=int(input(Number of sides))
class polygon(object):
    def __init__(self,x):                                       #useless code
        self.x=x                                                            #useless code
        self.x=[]                                                           #useless code
    def __inputSides__(self):
        #counter=0
        #for i in range(x):
        #   counter=counter+1

        numSides=int(input("number of sides"))
        list_=[]
        for i in range(numSides):
            length=float(input("length"))
            list_.append(length)
        return list_

    def __dispSides__(self,list_):
        for i in list_:
            print("side length",i)

stone= polygon()
stone.__dispSides__(4)

but then in the second to last line i was getting an error that said :

Traceback (most recent call last):
  File "python", line 23, in <module>
TypeError: __init__() missing 1 required positional argument: 'x'

I was wondering how can i fix this and why I am getting this error?

thanks!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302757 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO