NEED HELP WITH TURTLE FUNCTION!! URGENT - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

NEED HELP WITH TURTLE FUNCTION!! URGENT

kevinlaikevinlai Posts: 2Member
I want to bubble sort the list the user has typed and then use the numbers in the list, for example [20, 50, 70], as the height of my graphic(supposed it's a rectangle). The original rectangles are in blue. then the program will do the sorting for every pass, If I want to change the color of the swapping rectangle into green. What should I type in my code? Where should I add in the code?

Here is some code I have come up with so far:

def drawAction(lst, width):
for height in lst:
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.pencolor("")
t.forward(30)
t.pencolor("black")
t.fill(False)


def drawAction_color(fillcolor):
t.fillcolor(fillcolor)
t.fill(True)


def swap(lst):
length = len(lst)
for i in range(0, length):
for n in range(0, length-i-1):
if lst[i] > lst[i+1]:
lst[i], lst[i+1] = lst[i+1], lst[i]
break

return lst


# TOP LEVEL
import turtle as t
lst = input("Provide list to be sorted: ")
width = input("Provide width ")
drawAction_color("blue")
for n in range(len(lst)):
drawAction(lst, width)
cont = raw_input("hit any key to continue ")
t.home()
t.clear()
drawAction_color("green")
swap(lst)

Sign In or Register to comment.