simple CLASS in python -



simple CLASS in python -

from math import pi class sphere(object): def __init__(self,radius): self.radius = radius def get_radius(self): homecoming radius def surfacearea(self): homecoming 4*pi*radius**2 def volume(self): homecoming (4//3)*pi*radius**3 radius = input("please come in radius:") print sphere.get_radius() print sphere.surfacearea() print sphere.volume()

i need write programme prompts user radius uses sphere class output surface area , volume of sphere. , type error unbound method get_radius() must called sphere instance first argument(got nil instead). way solve problemo?

you have never created object class sphere. instead of calling sphere.get_radius(), need first initiate object class, phone call method on object.

a = sphere(radius) # initiate object of class sphere called a.get_radius() # phone call method on object a.

python

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -