Mar-01-2020, 01:48 PM
This is going really into strange direction.
@jefsummers - what is the purpose of g.go property? and the class - as it is it defy the purpose of class.
to answer original question - as suggested by @ndc85430, you can use
@jefsummers - what is the purpose of g.go property? and the class - as it is it defy the purpose of class.
to answer original question - as suggested by @ndc85430, you can use
if __name__ == '__main__':
blockfrom math import pi def circle_area(r): return pi * (r ** 2) def circle_circumference(r): return 2 * pi * r if __name__ == "__main__": radius = float(input("Enter radius: ")) print("Area =", circle_area(radius)) print("Circumference =", circle_circumference(radius))now, if it has to be class:
from math import pi class Circle(): def __init__(self, radius): self.radius = radius @property def area(self): return pi * (self.radius ** 2) @property def circumference(self): return 2 * pi * self.radius if __name__ == "__main__": radius = float(input("Enter radius: ")) circle = Circle(radius) # create instance of Circle class print("Area =", circle.area) print("Circumference =", circle.circumference)in both cases nothing will happen if you import the module - functions and the class will be available to use in the other module, but the code in the
if __name__ == '__main__':
block will not be executed
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs