Dhr1 Dhr1 - 1 year ago 64
Python Question

How do I group all my functions in Python into one function?

I am using the Turtles Module where I am creating a U.S. Flag. The user decides the size of the flag and with that size I will be using it to create the width and length.

I am trying to group/compress all of my subfunctions into one huge function so the user can simply type

Draw_USAFlag(t, w) ## T = turtle W = Size
and it will carry out the task of the 5 functions that I already have.

For example I have 2 subfunctions:
draw_rectangle(t, w)
draw_stripes (t, w) ;
I want to group these two subfunctions into one function that will be called
Draw_USAFlag(t, w)
where it will use the user inputted
size (w)
throughout all of the functions. Any help is greatly appreciated! Thanks!

Answer Source

Quite simply, make a function that calls the others:

def draw_rectangle(t, w):
    # however you do this

def draw_rectangle(t, w):
    # however you do this

def Draw_USAFlag(t, w):
    draw_rectangle(t, w)
    draw_stripes(t, w)

This assumes they don't return anything, so whatever they do works by side-effects on some other object. If e.g. they return an image, this will need changing depending on the exact structure of your system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download