[Solved] Python-Turtle: Turning list of Strings into a working code


#example of the list being used

conundrum = ['black pen',
'lift pen',
['go to', -98, 132],
['draw dot', 10],
'lift pen',
['go to', -120, 137],
['draw dot', 10],
'lift pen',
'thick lines',
['go to', -55, 80],
'lower pen']

#Import everything from the turtle library
from turtle import *

#Define the draw function

def draw(test):
    home()
    #'total' is used as the amount of loops left
    # and amount of strings left to test
    #'current_num' is set as the current string
    # being tested starting from the first in
    # the list.
    total = len(test)
    current_num = 0
    bgcolor('black')

    # A while loop is set to run until total = 0
    #which means all strings have been checked

    while total > 0:
        #A set of if/elif statements to determine
        #what each string is and what statement
        #to use given that string

        if test[current_num] == 'lift pen':
            pu()

        elif test[current_num] == 'lower pen':
            pd()

        elif test[current_num] == 'thin lines':
            pensize(1)

        elif test[current_num] == 'thick lines':
            pensize(5)

        elif test[current_num] == 'black pen':
            color('black')

        elif test[current_num] == 'coloured pen':
            color('blue')

        #This last elif statement, tests to see if
        # it is a list rather than a string

        elif type(test[current_num]) == list:

            #As there are only 2 types of lists
            #one with 3 variables and the other with two
            #a test to determine which has 3 is run.

            if len(test[current_num]) == 3:

                # if this is true then the list is the goto() list
                # so the second variable in the list is set as x
                # and the third variable as y in goto(x,y)

                goto((test[current_num][1]),(test[current_num][2]))

            #else it is the dot() list

            else:

                 dot(test[current_num][1])

        #A final backup else statement that will print any strings that
        #dont follow with the set if statements so it can be fixed

        else:
            print test[current_num]

        #at the end of each loop the current_num is raised so the next
        #string will be tested while the total is reduced so that the
        #program can stop when it reaches 0

        current_num = current_num + 1 
        total = total - 1
    hideturtle()
    done()

And then all that i do is call the draw function and it works

solved Python-Turtle: Turning list of Strings into a working code