Mar-01-2020, 01:20 PM
(This post was last modified: Mar-01-2020, 01:21 PM by jefsummers.)
When you call the ScriptEnv.circle_area() function, you are only calling that particular function in the module, and the input line you have above does not get executed.
I suggest defining a class. Something like this (untested)
One oops from not testing - need self. in front of the go's in the functions within the class
I suggest defining a class. Something like this (untested)
class geometry: from math import pi def __init__(self) self.go = False def circle_area(r): if go: return pi * (r ** 2) def circle_circumference(r): if go: return 2 * pi * rWhich is then called by
import geometry def main(g): print("Running the main function") radius = float(input("Enter radius: ")) print("Area =", g.circle_area(radius)) print("Circumference =", g.circle_circumference(radius)) if __name__ == "__main__": g = geometry() g.go = True main(g)Dunder Main creates the geometry object and sets go to true, and passes the g object to main(). Function calls are then to the g object. If a geometry object is created elsewhere the default value for go is False, and nothing will print out. Malformed calls to the g object will still give error messages, as in the case of not passing a parameter.
One oops from not testing - need self. in front of the go's in the functions within the class