Skip to content

Instantly share code, notes, and snippets.

@sahilsinha sahilsinha/race.py

Created Dec 9, 2015
Embed
What would you like to do?
import turtle
import random
def main():
turtle1 = turtle.Turtle()
turtle2 = turtle.Turtle()
turtle3 = turtle.Turtle()
turtle4 = turtle.Turtle()
turtle1_distance = random.randrange(100)
turtle2_distance = random.randrange(100)
turtle3_distance = random.randrange(100)
turtle4_distance = random.randrange(100)
turtle1.forward(turtle1_distance)
turtle2.forward(turtle2_distance)
turtle3.forward(turtle3_distance)
turtle4.forward(turtle4_distance)
results = [turtle1_distance,turtle2_distance,turtle3_distance,turtle4_distance]
ordered_results = bubble_sort(results)
print ordered_results
def bubble_sort(items):
""" Implementation of bubble sort """
for i in range(len(items)):
for j in range(len(items)-1-i):
if items[j] > items[j+1]:
items[j], items[j+1] = items[j+1], items[j]
return items
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.