You code consists of a few parts.
Section 1:
chart_title = 'Tourism GDP by States/Territories in Australia'
segment_labels = ['QLD', 'VIC', 'NSW', 'SA', 'WA', 'TAS', 'NT', 'ACT']
percentages = [0.24, 0.22, 0.328, 0.06, 0.082, 0.03, 0.02, 0.02]
radius = 200
Section 2:
from turtle import *
Section 3:
penup()
forward(radius)
left(90)
pendown()
color('palegreen')
begin_fill()
circle(radius)
end_fill()
home()
right(90)
color('black')
section 4:
def segment(percentages):
rollingPercent = 0
radius=200
for percent in percentages:
segment = percent * 360
rollingPercent += segment
setheading(rollingPercent)
pendown()
forward(radius)
penup()
home()
In section one, you define some variables
In section two you import the turtle
module (library)
In section 3 you execute some functions from the turtle library which draw a green circle
Now the important bit. In section 4, you define a function (called segment
) which can draw segments. However, it will not draw segments until you explicitly ask it to. If you aren't familiar with what a function is, you should read some tutorials on the matter. They are quite important to understand (see here, here and here).
So while your function to draw segments has been defined, you are not calling the function (running the code in the function). Your function takes one argument (parameter) percentages
which is a list of percentages for the segments. Note the variable name percentages
in this case refers to a local variable that only exists within the function segment
, it does not necessarily refer to the list you define in section 1 of your code (but it can). To understand what I mean about local variables, read this.
So you need to call your function. To do this, you'll need to add the line of code segment(percentages)
, which calls the function segment
and passes in the list of percentages
as an argument.
Full code:
chart_title = 'Tourism GDP by States/Territories in Australia'
segment_labels = ['QLD', 'VIC', 'NSW', 'SA', 'WA', 'TAS', 'NT', 'ACT']
percentages = [0.24, 0.22, 0.328, 0.06, 0.082, 0.03, 0.02, 0.02]
from turtle import *
radius = 200
penup()
forward(radius)
left(90)
pendown()
color('palegreen')
begin_fill()
circle(radius)
end_fill()
home()
right(90)
color('black')
def segment(percentages):
rollingPercent = 0
radius=200
for percent in percentages:
segment = percent * 360
rollingPercent += segment
setheading(rollingPercent)
pendown()
forward(radius)
penup()
home()
segment(percentages)
It seems pretty clear from your comments that you need to familiarise yourself with functions in Python, so I suggest reading some tutorials and getting the basics down. It will make life easier in the future and really open up the capabilities of programming to you.