Instructions for shapeSorter

(produced at 00:48 a.m. UTC on 2024-11-01)

This task is part of project08 which is due at 23:00 EST on 2024-11-05.

You have the option to work with a partner on this task if you wish. Working with a partner requires more work to coordinate schedules, but if you work together and make sure that you are both understanding the code you write, you will make progress faster and learn more.

You can download the starter code for this task using this link.

You can submit this task using this link.

Put all of your work for this task into the file shapeSorter.py
(which is provided among the starter files)

This project is very similar the measureMunger task which uses wavesynth to generate audio instead of turtle to make pictures. You only have to do one of the two.

In this task you will define a number of short functions divided into several groups, to help you practice using list comprehensions and sorting:

  • List-builder functions:
    • makeTrianglesList
    • makeSquaresList
    • makeListWithColors
    • makeShapesList
  • List-filtering functions:
    • oddSideShapes
    • shapesWithColor
    • shapesThatFit
  • Sorting helper functions:
    • getColorAndSides
    • getAreaSizeAndSides
  • Sorting functions:
    • sortBySides
    • sortByColor
    • sortByArea
  • Final drawing function:
    • drawPolygonSequence

Almost all of these functions can be written in just one or two lines of code. We have provided a few helper functions that you will need for several of your functions:

  • polygonRadius which can compute the radius of a circle required to fit a polygon inside it.
  • polygonArea which can compute the area of a polygon.
  • customPolygon which can draw a custom polygon.
  • drawTest which will use many of your functions together to draw a few rows of polygons and test everything out (we have also provided a test_shapeSorter.py file for local testing).

As usual, each function you write must be documented.

Specifications

A key concept in this project is a specification: a tuple of values that specify each argument for a function. The function in this case is customPolygon, which has three parameters: the number of sides, the length of each side, and the color to use. That means that each specification is a tuple with 3 elements. For example, the tuple:

(3, 100, 'blue')

specifies that a triangle should be drawn (3 sides) where each side has length 100 and the whole thing is drawn in blue. If we have a specification stored in a variable, we can use indexing or unpacking to access the individual parts, like so:

spec = (3, 100, 'blue')
# Indexing to get parts of tuple:
sides = spec[0]
sideLength = spec[1]
useColor = spec[2]
# Unpacking to get parts of tuple:
sides, sideLength, useColor = spec

When the time comes to actually call customPolygon using a specification, we will need to unpack it so that we can provide each argument to customPolygon one at a time. If we have individual variables and want to create a specification, we can just use parentheses and commas, like so:

myColor = 'red'
mySides = 4
myLength = 30
mySpec = (mySides, myLength, myColor)  # order is important here

Most functions in this assignment will deal with specifications one way or another.

Part A: List-building functions

For each list-building function, you will define a function that takes a few parameters and builds and returns a list of specification tuples (see above) using a list comprehension:

As usual, refer to the examples section for concrete examples of how these functions should work.

Part B: List-filtering functions

For each list-filtering function, you will define a function that takes a few parameters and returns a new list of specification tuples (see above) based on filtering out some of the provided specifications using a list comprehension :

Sorting Reminders

As you know, in order to do any custom sorting we need to define a key function that will take in one element being sorted and return a "key" object that determines how that element will get sorted (the rest of the sorting process is automatic).

For example, if our key function was the following:

def characterKey(character):
    if character == 'C':
        return 1
    elif character == 'S':
        return 2
    elif character == '1':
        return 100

then if we called .sort using that function like this:

letters = ['1', 'C', '1', 'S', '1']
letters.sort(key=characterKey)
print(letters)

We'd see the following output:

['C', 'S', '1', '1', '1']

That's because Python orders the key values from lowest to highest, and then arranges the original items based on where their key values end up. Since our characterKey function returns the number 1 as the key for the letter 'C', and that's smaller than the keys for the other letters we use, that letter ends up first in the result, etc.

As an additional reminder, to break ties when sorting, if the key value is a tuple or some other kind of sequence (including a string), Python tries to sort using just the first element of the sequence, then breaks ties based on the ordering of the second elements of each key, then breaks double-ties based on the third elements, and so on. So you can use tuples as the return value from a key function to specify both primary sort order (using first element of the tuple) and secondary sort orders in case of ties (using subsequent elements).

Part C: Sorting helper functions

For the next part, you'll define the key functions that we'll use to sort with:

Part D: Sorting functions

Now that you have helper functions ready, you'll define some sorting functions which can be used to re-order specification lists. These functions will NOT return anything because they will directly re-arrange the specifications list they are given . Each of these functions must call the .sort list method , and they may not use any loops (which aren't necessary).

Part E: Drawing from specifications

For the final part of this project, you have to implement a drawPolygonSequence function which takes a specifications list, a spacing value, and a height and draws each specified polygon spaced out at the given height.

Each polygon is drawn centered at the specified y coordinate, and the x-coordinates of their centers are spaced out by the given spacing value. The polygons are drawn from the left to the right, in the same order of the specifications list. The entire line of polygons is centered around x=0.

For example:

  • If there are two polygons with spacing of 100 and height 75, they will be drawn centered at (-50, 75) and (50, 75).
  • If there are three polygons with spacing 80 and height -111, they will be drawn centered at (-80, -111), (0, -111), and (80, -111).

You will get some credit as long as you draw the right number of polygons. drawPolygonSequence must:

Notes

  • As in other assignments, there is an extra goal to not waste the results of fruitful functions, but for this project the "don't waste boxes" goal is not used, since we might want to unpack a multi-part variable but then ignore some parts of it.

Examples

makeTrianglesList examples

These examples show what makeTrianglesList should return.

In []:
makeTrianglesList(['red', 'blue', 'black'])
Out[]:
[(3, 50, 'red'), (3, 50, 'blue'), (3, 50, 'black')]
In []:
makeTrianglesList(['green', 'SpringGreen', 'SeaGreen'])
Out[]:
[(3, 50, 'green'), (3, 50, 'SpringGreen'), (3, 50, 'SeaGreen')]
In []:
makeTrianglesList(['green'])
Out[]:
[(3, 50, 'green')]

makeSquaresList examples

These examples show what makeSquaresList should return.

In []:
makeSquaresList('orange', [10, 20, 30])
Out[]:
[(4, 10, 'orange'), (4, 20, 'orange'), (4, 30, 'orange')]
In []:
makeSquaresList('DarkOrchid', [50, 45, 40])
Out[]:
[(4, 50, 'DarkOrchid'), (4, 45, 'DarkOrchid'), (4, 40, 'DarkOrchid')]
In []:
makeSquaresList('DodgerBlue', [20, 30, 20, 30])
Out[]:
[ (4, 20, 'DodgerBlue'), (4, 30, 'DodgerBlue'), (4, 20, 'DodgerBlue'), (4, 30, 'DodgerBlue'), ]

makeListWithColors examples

These examples show what makeListWithColors should return.

In []:
makeListWithColors([(8, 10), (6, 20), (4, 30)], 'SeaGreen')
Out[]:
[(8, 10, 'SeaGreen'), (6, 20, 'SeaGreen'), (4, 30, 'SeaGreen')]
In []:
makeListWithColors([(3, 50), (3, 45), (4, 40)], 'Aquamarine')
Out[]:
[(3, 50, 'Aquamarine'), (3, 45, 'Aquamarine'), (4, 40, 'Aquamarine')]
In []:
makeListWithColors([(5, 20), (7, 30), (7, 20), (5, 30)], 'Khaki')
Out[]:
[(5, 20, 'Khaki'), (7, 30, 'Khaki'), (7, 20, 'Khaki'), (5, 30, 'Khaki')]

makeShapesList examples

These examples show what makeShapesList should return.

In []:
makeShapesList([8, 6, 4], [10, 20, 30], ['SeaGreen', 'LimeGreen', 'PaleGreen'])
Out[]:
[(8, 10, 'SeaGreen'), (6, 20, 'LimeGreen'), (4, 30, 'PaleGreen')]
In []:
makeShapesList( [4, 6, 8, 6, 7, 5, 5], [50, 30, 25, 35, 35, 40, 30], [ 'Firebrick', 'Khaki', 'DeepSkyBlue', 'SeaGreen', 'Khaki', 'DeepSkyBlue', 'DarkOrchid', ] )
Out[]:
[ (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid'), ]
In []:
makeShapesList([4], [100], ['black'])
Out[]:
[(4, 100, 'black')]

oddSideShapes examples

These examples show what oddSideShapes should return.

In []:
oddSideShapes( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ] )
Out[]:
[ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ]
In []:
oddSideShapes( [ (3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70'), ] )
Out[]:
[(3, 20, 'gray30'), (5, 28, 'gray70'), (7, 36, 'gray30'), (9, 44, 'gray70')]
In []:
oddSideShapes( [ (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid'), ] )
Out[]:
[(7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid')]

shapesWithColor examples

These examples show what shapesWithColor should return.

In []:
shapesWithColor( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 'pink' )
Out[]:
[(3, 35, 'pink'), (3, 45, 'pink'), (3, 40, 'pink')]
In []:
shapesWithColor( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 'LightSkyBlue' )
Out[]:
[(3, 25, 'LightSkyBlue'), (3, 35, 'LightSkyBlue')]
In []:
shapesWithColor( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 'black' )
Out[]:
[]

shapesThatFit examples

These examples show what shapesThatFit should return.

In []:
shapesThatFit( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 15 )
Out[]:
[(3, 20, 'SpringGreen'), (3, 25, 'LightSkyBlue')]
In []:
shapesThatFit( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 20 )
Out[]:
[(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue')]
In []:
shapesThatFit( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 100 )
Out[]:
[ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ]

getColorAndSides examples

These examples show what getColorAndSides should return.

In []:
getColorAndSides((3, 20, 'SpringGreen'))
Out[]:
('SpringGreen', 3)
In []:
getColorAndSides((3, 35, 'pink'))
Out[]:
('pink', 3)
In []:
getColorAndSides((8, 25, 'DeepSkyBlue'))
Out[]:
('DeepSkyBlue', 8)

getAreaSizeAndSides examples

These examples show what getAreaSizeAndSides should return.

In []:
getAreaSizeAndSides((3, 20, 'SpringGreen'))
Out[]:
(173.20508075688775, 20, 3)
In []:
getAreaSizeAndSides((3, 35, 'pink'))
Out[]:
(530.4405598179688, 35, 3)
In []:
getAreaSizeAndSides((8, 25, 'DeepSkyBlue'))
Out[]:
(3017.766952966369, 25, 8)

drawPolygonSequence examples

These examples show what should be drawn when drawPolygonSequence is called. Note that the final position of the turtle is not important.

In []:
drawPolygonSequence( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 100, 130 )
Prints
Start of filled shape. A 1-pensize SpringGreen triangle with side length 20 centered at (-300, 130) with a flat side facing North. Filled in shape using SpringGreen. Start of filled shape. A 1-pensize SpringGreen triangle with side length 30 centered at (-200, 130) with a flat side facing North. Filled in shape using SpringGreen. Start of filled shape. A 1-pensize LightSkyBlue triangle with side length 25 centered at (-100, 130) with a flat side facing North. Filled in shape using LightSkyBlue. Start of filled shape. A 1-pensize pink triangle with side length 35 centered at (0, 130) with a flat side facing North. Filled in shape using pink. Start of filled shape. A 1-pensize pink triangle with side length 45 centered at (100, 130) with a flat side facing North. Filled in shape using pink. Start of filled shape. A 1-pensize LightSkyBlue triangle with side length 35 centered at (200, 130) with a flat side facing North. Filled in shape using LightSkyBlue. Start of filled shape. A 1-pensize pink triangle with side length 40 centered at (300, 130) with a flat side facing North. Filled in shape using pink.
Image Start of filled shape.
A 1-pensize SpringGreen triangle with side length 20 centered at (-300, 130) with a flat side facing North.
Filled in shape using SpringGreen.
Start of filled shape.
A 1-pensize SpringGreen triangle with side length 30 centered at (-200, 130) with a flat side facing North.
Filled in shape using SpringGreen.
Start of filled shape.
A 1-pensize LightSkyBlue triangle with side length 25 centered at (-100, 130) with a flat side facing North.
Filled in shape using LightSkyBlue.
Start of filled shape.
A 1-pensize pink triangle with side length 35 centered at (0, 130) with a flat side facing North.
Filled in shape using pink.
Start of filled shape.
A 1-pensize pink triangle with side length 45 centered at (100, 130) with a flat side facing North.
Filled in shape using pink.
Start of filled shape.
A 1-pensize LightSkyBlue triangle with side length 35 centered at (200, 130) with a flat side facing North.
Filled in shape using LightSkyBlue.
Start of filled shape.
A 1-pensize pink triangle with side length 40 centered at (300, 130) with a flat side facing North.
Filled in shape using pink.
In []:
drawPolygonSequence( [ (3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70'), ], 90, 0 )
Prints
Start of filled shape. A 1-pensize gray30 triangle with side length 20 centered at (-270, 0) with a flat side facing North. Filled in shape using gray30. Start of filled shape. A 1-pensize gray70 quadrilateral with side length 24 centered at (-180, 0) with a flat side facing North. Filled in shape using gray70. Start of filled shape. A 1-pensize gray70 pentagon with side length 28 centered at (-90, 0) with a flat side facing North. Filled in shape using gray70. Start of filled shape. A 1-pensize gray70 hexagon with side length 32 centered at (0, 0) with a flat side facing North. Filled in shape using gray70. Start of filled shape. A 1-pensize gray30 heptagon with side length 36 centered at (90, 0) with a flat side facing North. Filled in shape using gray30. Start of filled shape. A 1-pensize gray30 octagonnonagon with side length 40 centered at (180, 0) with a flat side facing North. Filled in shape using gray30. Start of filled shape. A 1-pensize gray70 decagon with side length 44 centered at (270, 0) with a flat side facing North. Filled in shape using gray70.
Image Start of filled shape.
A 1-pensize gray30 triangle with side length 20 centered at (-270, 0) with a flat side facing North.
Filled in shape using gray30.
Start of filled shape.
A 1-pensize gray70 quadrilateral with side length 24 centered at (-180, 0) with a flat side facing North.
Filled in shape using gray70.
Start of filled shape.
A 1-pensize gray70 pentagon with side length 28 centered at (-90, 0) with a flat side facing North.
Filled in shape using gray70.
Start of filled shape.
A 1-pensize gray70 hexagon with side length 32 centered at (0, 0) with a flat side facing North.
Filled in shape using gray70.
Start of filled shape.
A 1-pensize gray30 heptagon with side length 36 centered at (90, 0) with a flat side facing North.
Filled in shape using gray30.
Start of filled shape.
A 1-pensize gray30 octagonnonagon with side length 40 centered at (180, 0) with a flat side facing North.
Filled in shape using gray30.
Start of filled shape.
A 1-pensize gray70 decagon with side length 44 centered at (270, 0) with a flat side facing North.
Filled in shape using gray70.
In []:
drawPolygonSequence( [ (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid'), ], 120, -130 )
Prints
Start of filled shape. A 1-pensize Firebrick quadrilateral with side length 50 centered at (-360, -130) with a flat side facing North. Filled in shape using Firebrick. Start of filled shape. A 1-pensize Khaki hexagon with side length 30 centered at (-240, -130) with a flat side facing North. Filled in shape using Khaki. Start of filled shape. A 1-pensize DeepSkyBlue octagonnonagon with side length 25 centered at (-120, -130) with a flat side facing North. Filled in shape using DeepSkyBlue. Start of filled shape. A 1-pensize SeaGreen hexagon with side length 35 centered at (0, -130) with a flat side facing North. Filled in shape using SeaGreen. Start of filled shape. A 1-pensize Khaki heptagon with side length 35 centered at (120, -130) with a flat side facing North. Filled in shape using Khaki. Start of filled shape. A 1-pensize DeepSkyBlue pentagon with side length 40 centered at (240, -130) with a flat side facing North. Filled in shape using DeepSkyBlue. Start of filled shape. A 1-pensize DarkOrchid pentagon with side length 30 centered at (360, -130) with a flat side facing North. Filled in shape using DarkOrchid.
Image Start of filled shape.
A 1-pensize Firebrick quadrilateral with side length 50 centered at (-360, -130) with a flat side facing North.
Filled in shape using Firebrick.
Start of filled shape.
A 1-pensize Khaki hexagon with side length 30 centered at (-240, -130) with a flat side facing North.
Filled in shape using Khaki.
Start of filled shape.
A 1-pensize DeepSkyBlue octagonnonagon with side length 25 centered at (-120, -130) with a flat side facing North.
Filled in shape using DeepSkyBlue.
Start of filled shape.
A 1-pensize SeaGreen hexagon with side length 35 centered at (0, -130) with a flat side facing North.
Filled in shape using SeaGreen.
Start of filled shape.
A 1-pensize Khaki heptagon with side length 35 centered at (120, -130) with a flat side facing North.
Filled in shape using Khaki.
Start of filled shape.
A 1-pensize DeepSkyBlue pentagon with side length 40 centered at (240, -130) with a flat side facing North.
Filled in shape using DeepSkyBlue.
Start of filled shape.
A 1-pensize DarkOrchid pentagon with side length 30 centered at (360, -130) with a flat side facing North.
Filled in shape using DarkOrchid.

sortBySides examples

These examples show how the order of the target list should be modified when calling sortBySides. Remember that sortBySides is NOT supposed to use return but should instead modify the order of the list it's given using the .sort method. The prints here are part of our testing setup; your sortBySides function does NOT need to print anything.

In []:
specifications = [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] print("Before sorting we have:") print(specifications) returned = sortBySides(specifications, True) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] After sorting we get: [(3, 20, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 30, 'SpringGreen'), (3, 35, 'LightSkyBlue'), (3, 35, 'pink'), (3, 40, 'pink'), (3, 45, 'pink')]
In []:
specifications = [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] print("Before sorting we have:") print(specifications) returned = sortBySides(specifications, False) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] After sorting we get: [(3, 45, 'pink'), (3, 40, 'pink'), (3, 35, 'pink'), (3, 35, 'LightSkyBlue'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 20, 'SpringGreen')]
In []:
specifications = [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] print("Before sorting we have:") print(specifications) returned = sortBySides(specifications, True) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] After sorting we get: [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')]
In []:
specifications = [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] print("Before sorting we have:") print(specifications) returned = sortBySides(specifications, False) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] After sorting we get: [(9, 44, 'gray70'), (8, 40, 'gray30'), (7, 36, 'gray30'), (6, 32, 'gray70'), (5, 28, 'gray70'), (4, 24, 'gray70'), (3, 20, 'gray30')]

sortByColor examples

These examples show how the order of the target list should be modified when calling sortByColor. Remember that sortByColor is NOT supposed to use return but should instead modify the order of the list it's given using the .sort method. The prints here are part of our testing setup; your sortByColor function does NOT need to print anything.

In []:
specifications = [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] print("Before sorting we have:") print(specifications) returned = sortByColor(specifications) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] After sorting we get: [(3, 25, 'LightSkyBlue'), (3, 35, 'LightSkyBlue'), (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 40, 'pink')]
In []:
specifications = [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] print("Before sorting we have:") print(specifications) returned = sortByColor(specifications) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] After sorting we get: [(3, 20, 'gray30'), (7, 36, 'gray30'), (8, 40, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (9, 44, 'gray70')]
In []:
specifications = [(4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid')] print("Before sorting we have:") print(specifications) returned = sortByColor(specifications) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid')] After sorting we get: [(5, 30, 'DarkOrchid'), (5, 40, 'DeepSkyBlue'), (8, 25, 'DeepSkyBlue'), (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (7, 35, 'Khaki'), (6, 35, 'SeaGreen')]

sortByArea examples

These examples show how the order of the target list should be modified when calling sortByArea. Remember that sortByArea is NOT supposed to use return but should instead modify the order of the list it's given using the .sort method. The prints here are part of our testing setup; your sortByArea function does NOT need to print anything.

In []:
specifications = [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] print("Before sorting we have:") print(specifications) returned = sortByArea(specifications) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink')] After sorting we get: [(3, 20, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 30, 'SpringGreen'), (3, 35, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), (3, 45, 'pink')]
In []:
specifications = [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] print("Before sorting we have:") print(specifications) returned = sortByArea(specifications) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')] After sorting we get: [(3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70')]
In []:
specifications = [(4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid')] print("Before sorting we have:") print(specifications) returned = sortByArea(specifications) if returned != None: print('Oops, the sorting function had a return value!') print("After sorting we get:") print(specifications)
Prints
Before sorting we have: [(4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid')] After sorting we get: [(5, 30, 'DarkOrchid'), (6, 30, 'Khaki'), (4, 50, 'Firebrick'), (5, 40, 'DeepSkyBlue'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki')]

drawTest example

Although the code for drawTest was provided with the starter code, it won't work until all of your other functions are working. This shows what the result should look like when drawTest is run after your project is complete. You can visually see the results of the various sorting functions used by drawTest.

In []:
drawTest()
Prints
Start of filled shape. A 1-pensize LightSkyBlue triangle with side length 50 centered at (-300, 200) with a flat side facing North. Filled in shape using LightSkyBlue. Start of filled shape. A 1-pensize LightSkyBlue triangle with side length 50 centered at (-200, 200) with a flat side facing North. Filled in shape using LightSkyBlue. Start of filled shape. A 1-pensize SpringGreen triangle with side length 50 centered at (-100, 200) with a flat side facing North. Filled in shape using SpringGreen. Start of filled shape. A 1-pensize pink triangle with side length 50 centered at (0, 200) with a flat side facing North. Filled in shape using pink. Start of filled shape. A 1-pensize pink triangle with side length 50 centered at (100, 200) with a flat side facing North. Filled in shape using pink. Start of filled shape. A 1-pensize yellow triangle with side length 50 centered at (200, 200) with a flat side facing North. Filled in shape using yellow. Start of filled shape. A 1-pensize yellow triangle with side length 50 centered at (300, 200) with a flat side facing North. Filled in shape using yellow. Start of filled shape. A 1-pensize orange quadrilateral with side length 20 centered at (-200, 100) with a flat side facing North. Filled in shape using orange. Start of filled shape. A 1-pensize orange quadrilateral with side length 25 centered at (-100, 100) with a flat side facing North. Filled in shape using orange. Start of filled shape. A 1-pensize orange quadrilateral with side length 30 centered at (0, 100) with a flat side facing North. Filled in shape using orange. Start of filled shape. A 1-pensize orange quadrilateral with side length 35 centered at (100, 100) with a flat side facing North. Filled in shape using orange. Start of filled shape. A 1-pensize orange quadrilateral with side length 35 centered at (200, 100) with a flat side facing North. Filled in shape using orange. Start of filled shape. A 1-pensize gray heptagon with side length 15 centered at (-100, 0) with a flat side facing North. Filled in shape using gray. Start of filled shape. A 1-pensize gray pentagon with side length 25 centered at (0, 0) with a flat side facing North. Filled in shape using gray. Start of filled shape. A 1-pensize gray triangle with side length 40 centered at (100, 0) with a flat side facing North. Filled in shape using gray. Start of filled shape. A 1-pensize DarkOrchid pentagon with side length 30 centered at (-300, -100) with a flat side facing North. Filled in shape using DarkOrchid. Start of filled shape. A 1-pensize Khaki hexagon with side length 30 centered at (-200, -100) with a flat side facing North. Filled in shape using Khaki. Start of filled shape. A 1-pensize Firebrick quadrilateral with side length 50 centered at (-100, -100) with a flat side facing North. Filled in shape using Firebrick. Start of filled shape. A 1-pensize DeepSkyBlue pentagon with side length 40 centered at (0, -100) with a flat side facing North. Filled in shape using DeepSkyBlue. Start of filled shape. A 1-pensize DeepSkyBlue octagonnonagon with side length 25 centered at (100, -100) with a flat side facing North. Filled in shape using DeepSkyBlue. Start of filled shape. A 1-pensize SeaGreen hexagon with side length 35 centered at (200, -100) with a flat side facing North. Filled in shape using SeaGreen. Start of filled shape. A 1-pensize Khaki heptagon with side length 35 centered at (300, -100) with a flat side facing North. Filled in shape using Khaki. Start of filled shape. A 1-pensize DarkOrchid pentagon with side length 30 centered at (-200, -200) with a flat side facing North. Filled in shape using DarkOrchid. Start of filled shape. A 1-pensize DeepSkyBlue pentagon with side length 40 centered at (-100, -200) with a flat side facing North. Filled in shape using DeepSkyBlue. Start of filled shape. A 1-pensize Khaki hexagon with side length 30 centered at (0, -200) with a flat side facing North. Filled in shape using Khaki. Start of filled shape. A 1-pensize Khaki heptagon with side length 35 centered at (100, -200) with a flat side facing North. Filled in shape using Khaki. Start of filled shape. A 1-pensize DeepSkyBlue octagonnonagon with side length 25 centered at (200, -200) with a flat side facing North. Filled in shape using DeepSkyBlue.
Image Start of filled shape.
A 1-pensize LightSkyBlue triangle with side length 50 centered at (-300, 200) with a flat side facing North.
Filled in shape using LightSkyBlue.
Start of filled shape.
A 1-pensize LightSkyBlue triangle with side length 50 centered at (-200, 200) with a flat side facing North.
Filled in shape using LightSkyBlue.
Start of filled shape.
A 1-pensize SpringGreen triangle with side length 50 centered at (-100, 200) with a flat side facing North.
Filled in shape using SpringGreen.
Start of filled shape.
A 1-pensize pink triangle with side length 50 centered at (0, 200) with a flat side facing North.
Filled in shape using pink.
Start of filled shape.
A 1-pensize pink triangle with side length 50 centered at (100, 200) with a flat side facing North.
Filled in shape using pink.
Start of filled shape.
A 1-pensize yellow triangle with side length 50 centered at (200, 200) with a flat side facing North.
Filled in shape using yellow.
Start of filled shape.
A 1-pensize yellow triangle with side length 50 centered at (300, 200) with a flat side facing North.
Filled in shape using yellow.
Start of filled shape.
A 1-pensize orange quadrilateral with side length 20 centered at (-200, 100) with a flat side facing North.
Filled in shape using orange.
Start of filled shape.
A 1-pensize orange quadrilateral with side length 25 centered at (-100, 100) with a flat side facing North.
Filled in shape using orange.
Start of filled shape.
A 1-pensize orange quadrilateral with side length 30 centered at (0, 100) with a flat side facing North.
Filled in shape using orange.
Start of filled shape.
A 1-pensize orange quadrilateral with side length 35 centered at (100, 100) with a flat side facing North.
Filled in shape using orange.
Start of filled shape.
A 1-pensize orange quadrilateral with side length 35 centered at (200, 100) with a flat side facing North.
Filled in shape using orange.
Start of filled shape.
A 1-pensize gray heptagon with side length 15 centered at (-100, 0) with a flat side facing North.
Filled in shape using gray.
Start of filled shape.
A 1-pensize gray pentagon with side length 25 centered at (0, 0) with a flat side facing North.
Filled in shape using gray.
Start of filled shape.
A 1-pensize gray triangle with side length 40 centered at (100, 0) with a flat side facing North.
Filled in shape using gray.
Start of filled shape.
A 1-pensize DarkOrchid pentagon with side length 30 centered at (-300, -100) with a flat side facing North.
Filled in shape using DarkOrchid.
Start of filled shape.
A 1-pensize Khaki hexagon with side length 30 centered at (-200, -100) with a flat side facing North.
Filled in shape using Khaki.
Start of filled shape.
A 1-pensize Firebrick quadrilateral with side length 50 centered at (-100, -100) with a flat side facing North.
Filled in shape using Firebrick.
Start of filled shape.
A 1-pensize DeepSkyBlue pentagon with side length 40 centered at (0, -100) with a flat side facing North.
Filled in shape using DeepSkyBlue.
Start of filled shape.
A 1-pensize DeepSkyBlue octagonnonagon with side length 25 centered at (100, -100) with a flat side facing North.
Filled in shape using DeepSkyBlue.
Start of filled shape.
A 1-pensize SeaGreen hexagon with side length 35 centered at (200, -100) with a flat side facing North.
Filled in shape using SeaGreen.
Start of filled shape.
A 1-pensize Khaki heptagon with side length 35 centered at (300, -100) with a flat side facing North.
Filled in shape using Khaki.
Start of filled shape.
A 1-pensize DarkOrchid pentagon with side length 30 centered at (-200, -200) with a flat side facing North.
Filled in shape using DarkOrchid.
Start of filled shape.
A 1-pensize DeepSkyBlue pentagon with side length 40 centered at (-100, -200) with a flat side facing North.
Filled in shape using DeepSkyBlue.
Start of filled shape.
A 1-pensize Khaki hexagon with side length 30 centered at (0, -200) with a flat side facing North.
Filled in shape using Khaki.
Start of filled shape.
A 1-pensize Khaki heptagon with side length 35 centered at (100, -200) with a flat side facing North.
Filled in shape using Khaki.
Start of filled shape.
A 1-pensize DeepSkyBlue octagonnonagon with side length 25 centered at (200, -200) with a flat side facing North.
Filled in shape using DeepSkyBlue.

Rubric

Group goals:
 
unknown All functions are documented
Each function you define must include a non-empty documentation string as the very first thing in the function.
 
unknown Do not ignore the results of any fruitful function calls
According to the "Don't waste fruit" principle, every place you call a fruitful function (built-in or custom) you must store the result in a variable, or that function call must be part of a larger expression that uses its return value.
 
unknown makeTrianglesList must return the correct result
The result returned when your makeTrianglesList function is run must match the solution result.
 
unknown makeSquaresList must return the correct result
The result returned when your makeSquaresList function is run must match the solution result.
 
unknown makeListWithColors must return the correct result
The result returned when your makeListWithColors function is run must match the solution result.
 
unknown makeShapesList must return the correct result
The result returned when your makeShapesList function is run must match the solution result.
 
unknown oddSideShapes must return the correct result
The result returned when your oddSideShapes function is run must match the solution result.
 
unknown shapesWithColor must return the correct result
The result returned when your shapesWithColor function is run must match the solution result.
 
unknown shapesThatFit must return the correct result
The result returned when your shapesThatFit function is run must match the solution result.
 
unknown getColorAndSides must return the correct result
The result returned when your getColorAndSides function is run must match the solution result.
 
unknown getAreaSizeAndSides must return the correct result
The result returned when your getAreaSizeAndSides function is run must match the solution result.
 
unknown sortBySides must modify its first argument correctly
We will call sortBySides with a test argument, and check to make sure that it modifies its first argument correctly. We will also make sure that the function returns None.
 
unknown sortByColor must modify its first argument correctly
We will call sortByColor with a test argument, and check to make sure that it modifies its first argument correctly. We will also make sure that the function returns None.
 
unknown sortByArea must modify its first argument correctly
We will call sortByArea with a test argument, and check to make sure that it modifies its first argument correctly. We will also make sure that the function returns None.
 
unknown drawPolygonSequence must make the correct number of calls to customPolygon
Your drawPolygonSequence function must call customPolygon the correct number of times.
 
unknown drawPolygonSequence must make the correct function calls
Your drawPolygonSequence function must call the customPolygon function in the correct order, with the correct arguments, while the correct position, pen_color, and fill_color values are set up
 
unknown drawTest must draw the correct image
The image drawn in the turtle window after drawTest is called must match the solution image.
 
unknown Define makeTrianglesList with 1 parameter
Use def to define makeTrianglesList with 1 parameter
 
unknown Use a comprehension
Within the definition of makeTrianglesList with 1 parameter, use a comprehension in at least one place.
 
unknown Define makeSquaresList with 2 parameters
Use def to define makeSquaresList with 2 parameters
 
unknown Use a comprehension
Within the definition of makeSquaresList with 2 parameters, use a comprehension in at least one place.
 
unknown Define makeListWithColors with 2 parameters
Use def to define makeListWithColors with 2 parameters
 
unknown Use a comprehension
Within the definition of makeListWithColors with 2 parameters, use a comprehension in at least one place.
 
unknown Define makeShapesList with 3 parameters
Use def to define makeShapesList with 3 parameters
 
unknown Use a comprehension
Within the definition of makeShapesList with 3 parameters, use a comprehension in at least one place.
 
unknown Call len
Within the definition of makeShapesList with 3 parameters, call len in at least one place.
 
unknown Call range
Within the definition of makeShapesList with 3 parameters, call range in at least one place.
 
unknown Define oddSideShapes with 1 parameter
Use def to define oddSideShapes with 1 parameter
 
unknown Use a comprehension
Within the definition of oddSideShapes with 1 parameter, use a comprehension in at least one place.
 
unknown Define shapesWithColor with 2 parameters
Use def to define shapesWithColor with 2 parameters
 
unknown Use a comprehension
Within the definition of shapesWithColor with 2 parameters, use a comprehension in at least one place.
 
unknown Define shapesThatFit with 2 parameters
Use def to define shapesThatFit with 2 parameters
 
unknown Use a comprehension
Within the definition of shapesThatFit with 2 parameters, use a comprehension in at least one place.
 
unknown Call polygonRadius
Within the definition of shapesThatFit with 2 parameters, call polygonRadius in at least one place.
 
unknown Define shapesThatFit with 2 parameters
Use def to define shapesThatFit with 2 parameters
 
unknown Use a comprehension
Within the definition of shapesThatFit with 2 parameters, use a comprehension in at least one place.
 
unknown Call polygonRadius
Within the comprehension within the definition of shapesThatFit with 2 parameters, call polygonRadius in at least one place.
 
unknown Define getColorAndSides with 1 parameter
Use def to define getColorAndSides with 1 parameter
 
unknown Do not use any kind of loop
Within the definition of getColorAndSides with 1 parameter, do not use any kind of loop.
 
unknown Define getAreaSizeAndSides with 1 parameter
Use def to define getAreaSizeAndSides with 1 parameter
 
unknown Do not use any kind of loop
Within the definition of getAreaSizeAndSides with 1 parameter, do not use any kind of loop.
 
unknown Call polygonArea
Within the definition of getAreaSizeAndSides with 1 parameter, call polygonArea in at least one place.
 
unknown Define sortBySides with 2 parameters
Use def to define sortBySides with 2 parameters
 
unknown Call sort
Within the definition of sortBySides with 2 parameters, call sort in at least one place.
 
unknown Do not use any kind of loop
Within the definition of sortBySides with 2 parameters, do not use any kind of loop.
 
unknown Do not use a return statement
Within the definition of sortBySides with 2 parameters, do not use return _.
 
unknown Define sortByColor with 1 parameter
Use def to define sortByColor with 1 parameter
 
unknown Call sort
Within the definition of sortByColor with 1 parameter, call sort in at least one place.
 
unknown Do not use any kind of loop
Within the definition of sortByColor with 1 parameter, do not use any kind of loop.
 
unknown Do not use a return statement
Within the definition of sortByColor with 1 parameter, do not use return _.
 
unknown Define sortByArea with 1 parameter
Use def to define sortByArea with 1 parameter
 
unknown Call sort
Within the definition of sortByArea with 1 parameter, call sort in at least one place.
 
unknown Do not use any kind of loop
Within the definition of sortByArea with 1 parameter, do not use any kind of loop.
 
unknown Do not use a return statement
Within the definition of sortByArea with 1 parameter, do not use return _.
 
unknown Define drawPolygonSequence with 3 parameters
Use def to define drawPolygonSequence with 3 parameters
 
unknown Use any kind of loop
Within the definition of drawPolygonSequence with 3 parameters, use any kind of loop in at least one place.
 
unknown Call teleport
Within the definition of drawPolygonSequence with 3 parameters, call teleport in at least one place.
 
unknown Do not call sort
Within the definition of drawPolygonSequence with 3 parameters, do not call sort.
 
unknown Call customPolygon
Within the definition of drawPolygonSequence with 3 parameters, call customPolygon in at least one place.
 
unknown Call noTrace
Within the definition of drawPolygonSequence with 3 parameters, call noTrace in at least one place.
 
unknown Call showPicture
Within the definition of drawPolygonSequence with 3 parameters, call showPicture in at least one place.
 
unknown Do not use a return statement
Within the definition of drawPolygonSequence with 3 parameters, do not use return _.