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:
makeTrianglesList
makeSquaresList
makeListWithColors
makeShapesList
oddSideShapes
shapesWithColor
shapesThatFit
getColorAndSides
getAreaSizeAndSides
sortBySides
sortByColor
sortByArea
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.
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.
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:
makeTrianglesList
takes a list of
colors and makes
specifications that each use 3 sides, 50 for the side length, and
then one of the colors from the colors list. The resulting list of
specifications will have the
same length as the colors list it's given.makeSquaresList
takes a single color string and a list of side
lengths and returns a
specifications list that uses 4 sides and the specified color for each
entry, with one of the side lengths from the lengths
list. This means that the number of
specifications will match the number of lengths provided.makeListWithColors
takes a list of partial specifications which are
pairs containing a number of sides and a side
length, along with a single color string as its second
argument. It must return
a specifications list where each entry uses the side count and
length from one of the partial specifications and includes the
common color as the third
element.makeShapesList
takes three lists: one of side counts, another of
side lengths, and a third of
colors. It can assume that each
list will have the same length, but it needs to use
len
and
range
along with a
list comprehension to zip all three lists together into a single
specifications list, where each entry
takes a side count, a side length, and a color from the same position
in all three input lists.As usual, refer to the examples section for concrete examples of how these functions should work.
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 :
oddSideShapes
just takes a specifications
list and returns a new list
that includes only specifications with an odd number-of-sides
value.shapesWithColor
takes a specifications list and a color
string and returns a new
list including only specifications that use the required
color.shapesThatFit
takes a specifications list and a radius
number and returns a new
list including only specifications whose polygon would fit into a
circle of the given radius. It must
call
polygonRadius
in order to help figure that out, and it should do so inside its
list
comprehension.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).
For the next part, you'll define the key functions that we'll use to sort with:
getColorAndSides
takes a single specification
tuple (see
above) and returns a tuple containing first the color and
then the number of sides. Because
this is a common point of confusion, remember that
getColorAndSides
does NOT need to use a
loop because it only
needs to process a single specification, and it will get
applied to a list of specifications automatically during the
sorting process.getAreaSizeAndSides
takes a single specification
tuple and returns a tuple
containing first the area of that polygon, then it's side-length, and
finally the number of sides it
has. It must call
polygonArea
and as with getColorAndSides
it does NOT need to use a
loop.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).
sortBySides
takes two parameters: a list of specifications and a
boolean
indicating whether to sort in ascending or descending
order. It sorts the specifications
by their natural order without using a
key function, sorting by number of sides, breaking ties by side
length, and breaking double-ties alphabetically by color name.sortByColor
just takes a specifications
list and sorts it alphabetically
by color name, breaking ties by the number of
sides. It will use the
getColorAndSides
function you defined earlier.sortByArea
just takes a specifications
list and sorts it by polygon area,
breaking ties by side length and then number of sides
. It will use the getAreaSizeAndSides
function you defined earlier.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:
You will get some credit as long as you draw the right number of
polygons. drawPolygonSequence
must:
noTrace
at
the start and call
showPicture
at the end so that drawing is instantaneous.sort
(it
doesn't need to, this is just a reminder of that).teleport
to position the turtle.customPolygon
to actually draw the polygon; it does NOT need to use drawPolygon
directly.return
.makeTrianglesList
examples
These examples show what makeTrianglesList
should return.
In []:Out[]:makeTrianglesList(['red', 'blue', 'black'])
In []:[(3, 50, 'red'), (3, 50, 'blue'), (3, 50, 'black')]
Out[]:makeTrianglesList(['green', 'SpringGreen', 'SeaGreen'])
In []:[(3, 50, 'green'), (3, 50, 'SpringGreen'), (3, 50, 'SeaGreen')]
Out[]:makeTrianglesList(['green'])
[(3, 50, 'green')]
makeSquaresList
examples
These examples show what makeSquaresList
should return.
In []:Out[]:makeSquaresList('orange', [10, 20, 30])
In []:[(4, 10, 'orange'), (4, 20, 'orange'), (4, 30, 'orange')]
Out[]:makeSquaresList('DarkOrchid', [50, 45, 40])
In []:[(4, 50, 'DarkOrchid'), (4, 45, 'DarkOrchid'), (4, 40, 'DarkOrchid')]
Out[]:makeSquaresList('DodgerBlue', [20, 30, 20, 30])
[ (4, 20, 'DodgerBlue'), (4, 30, 'DodgerBlue'), (4, 20, 'DodgerBlue'), (4, 30, 'DodgerBlue'), ]
makeListWithColors
examples
These examples show what makeListWithColors
should return.
In []:Out[]:makeListWithColors([(8, 10), (6, 20), (4, 30)], 'SeaGreen')
In []:[(8, 10, 'SeaGreen'), (6, 20, 'SeaGreen'), (4, 30, 'SeaGreen')]
Out[]:makeListWithColors([(3, 50), (3, 45), (4, 40)], 'Aquamarine')
In []:[(3, 50, 'Aquamarine'), (3, 45, 'Aquamarine'), (4, 40, 'Aquamarine')]
Out[]:makeListWithColors([(5, 20), (7, 30), (7, 20), (5, 30)], 'Khaki')
[(5, 20, 'Khaki'), (7, 30, 'Khaki'), (7, 20, 'Khaki'), (5, 30, 'Khaki')]
makeShapesList
examples
These examples show what makeShapesList
should return.
In []:Out[]:makeShapesList([8, 6, 4], [10, 20, 30], ['SeaGreen', 'LimeGreen', 'PaleGreen'])
In []:[(8, 10, 'SeaGreen'), (6, 20, 'LimeGreen'), (4, 30, 'PaleGreen')]
Out[]:makeShapesList( [4, 6, 8, 6, 7, 5, 5], [50, 30, 25, 35, 35, 40, 30], [ 'Firebrick', 'Khaki', 'DeepSkyBlue', 'SeaGreen', 'Khaki', 'DeepSkyBlue', 'DarkOrchid', ] )
In []:[ (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid'), ]
Out[]:makeShapesList([4], [100], ['black'])
[(4, 100, 'black')]
oddSideShapes
examples
These examples show what oddSideShapes
should return.
In []:Out[]:oddSideShapes( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ] )
In []:[ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ]
Out[]:oddSideShapes( [ (3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70'), ] )
In []:[(3, 20, 'gray30'), (5, 28, 'gray70'), (7, 36, 'gray30'), (9, 44, 'gray70')]
Out[]:oddSideShapes( [ (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid'), ] )
[(7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid')]
shapesWithColor
examples
These examples show what shapesWithColor
should return.
In []:Out[]:shapesWithColor( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 'pink' )
In []:[(3, 35, 'pink'), (3, 45, 'pink'), (3, 40, 'pink')]
Out[]:shapesWithColor( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 'LightSkyBlue' )
In []:[(3, 25, 'LightSkyBlue'), (3, 35, 'LightSkyBlue')]
Out[]:shapesWithColor( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 'black' )
[]
shapesThatFit
examples
These examples show what shapesThatFit
should return.
In []:Out[]:shapesThatFit( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 15 )
In []:[(3, 20, 'SpringGreen'), (3, 25, 'LightSkyBlue')]
Out[]:shapesThatFit( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 20 )
In []:[(3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue')]
Out[]:shapesThatFit( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 100 )
[ (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 []:Out[]:getColorAndSides((3, 20, 'SpringGreen'))
In []:('SpringGreen', 3)
Out[]:getColorAndSides((3, 35, 'pink'))
In []:('pink', 3)
Out[]:getColorAndSides((8, 25, 'DeepSkyBlue'))
('DeepSkyBlue', 8)
getAreaSizeAndSides
examples
These examples show what getAreaSizeAndSides
should return.
In []:Out[]:getAreaSizeAndSides((3, 20, 'SpringGreen'))
In []:(173.20508075688775, 20, 3)
Out[]:getAreaSizeAndSides((3, 35, 'pink'))
In []:(530.4405598179688, 35, 3)
Out[]:getAreaSizeAndSides((8, 25, 'DeepSkyBlue'))
(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 []:PrintsdrawPolygonSequence( [ (3, 20, 'SpringGreen'), (3, 30, 'SpringGreen'), (3, 25, 'LightSkyBlue'), (3, 35, 'pink'), (3, 45, 'pink'), (3, 35, 'LightSkyBlue'), (3, 40, 'pink'), ], 100, 130 )
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 In []:PrintsdrawPolygonSequence( [ (3, 20, 'gray30'), (4, 24, 'gray70'), (5, 28, 'gray70'), (6, 32, 'gray70'), (7, 36, 'gray30'), (8, 40, 'gray30'), (9, 44, 'gray70'), ], 90, 0 )
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 In []:PrintsdrawPolygonSequence( [ (4, 50, 'Firebrick'), (6, 30, 'Khaki'), (8, 25, 'DeepSkyBlue'), (6, 35, 'SeaGreen'), (7, 35, 'Khaki'), (5, 40, 'DeepSkyBlue'), (5, 30, 'DarkOrchid'), ], 120, -130 )
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
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:Printsspecifications = [(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)
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 []:PrintsdrawTest()
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
makeTrianglesList
must return the correct result
makeTrianglesList
function is run must match the solution result.makeSquaresList
must return the correct result
makeSquaresList
function is run must match the solution result.makeListWithColors
must return the correct result
makeListWithColors
function is run must match the solution result.makeShapesList
must return the correct result
makeShapesList
function is run must match the solution result.oddSideShapes
must return the correct result
oddSideShapes
function is run must match the solution result.shapesWithColor
must return the correct result
shapesWithColor
function is run must match the solution result.shapesThatFit
must return the correct result
shapesThatFit
function is run must match the solution result.getColorAndSides
must return the correct result
getColorAndSides
function is run must match the solution result.getAreaSizeAndSides
must return the correct result
getAreaSizeAndSides
function is run must match the solution result.sortBySides
must modify its first argument correctly
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.sortByColor
must modify its first argument correctly
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.sortByArea
must modify its first argument correctly
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.drawPolygonSequence
must make the correct number of calls to customPolygon
drawPolygonSequence
function must call customPolygon
the correct number of times.drawPolygonSequence
must make the correct function calls
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 updrawTest
must draw the correct image
drawTest
is called must match the solution image.makeTrianglesList
with 1 parameter
def
to define makeTrianglesList
with 1 parametermakeTrianglesList
with 1 parameter, use a comprehension in at least one place.makeSquaresList
with 2 parameters
def
to define makeSquaresList
with 2 parametersmakeSquaresList
with 2 parameters, use a comprehension in at least one place.makeListWithColors
with 2 parameters
def
to define makeListWithColors
with 2 parametersmakeListWithColors
with 2 parameters, use a comprehension in at least one place.makeShapesList
with 3 parameters
def
to define makeShapesList
with 3 parametersmakeShapesList
with 3 parameters, use a comprehension in at least one place.len
makeShapesList
with 3 parameters, call len
in at least one place.range
makeShapesList
with 3 parameters, call range
in at least one place.oddSideShapes
with 1 parameter
def
to define oddSideShapes
with 1 parameteroddSideShapes
with 1 parameter, use a comprehension in at least one place.shapesWithColor
with 2 parameters
def
to define shapesWithColor
with 2 parametersshapesWithColor
with 2 parameters, use a comprehension in at least one place.shapesThatFit
with 2 parameters
def
to define shapesThatFit
with 2 parametersshapesThatFit
with 2 parameters, use a comprehension in at least one place.polygonRadius
shapesThatFit
with 2 parameters, call polygonRadius
in at least one place.shapesThatFit
with 2 parameters
def
to define shapesThatFit
with 2 parametersshapesThatFit
with 2 parameters, use a comprehension in at least one place.polygonRadius
shapesThatFit
with 2 parameters, call polygonRadius
in at least one place.getColorAndSides
with 1 parameter
def
to define getColorAndSides
with 1 parametergetColorAndSides
with 1 parameter, do not use any kind of loop.getAreaSizeAndSides
with 1 parameter
def
to define getAreaSizeAndSides
with 1 parametergetAreaSizeAndSides
with 1 parameter, do not use any kind of loop.polygonArea
getAreaSizeAndSides
with 1 parameter, call polygonArea
in at least one place.sortBySides
with 2 parameters
def
to define sortBySides
with 2 parameterssort
sortBySides
with 2 parameters, call sort
in at least one place.sortBySides
with 2 parameters, do not use any kind of loop.return
statement
sortBySides
with 2 parameters, do not use return _
.sortByColor
with 1 parameter
def
to define sortByColor
with 1 parametersort
sortByColor
with 1 parameter, call sort
in at least one place.sortByColor
with 1 parameter, do not use any kind of loop.return
statement
sortByColor
with 1 parameter, do not use return _
.sortByArea
with 1 parameter
def
to define sortByArea
with 1 parametersort
sortByArea
with 1 parameter, call sort
in at least one place.sortByArea
with 1 parameter, do not use any kind of loop.return
statement
sortByArea
with 1 parameter, do not use return _
.drawPolygonSequence
with 3 parameters
def
to define drawPolygonSequence
with 3 parametersdrawPolygonSequence
with 3 parameters, use any kind of loop in at least one place.teleport
drawPolygonSequence
with 3 parameters, call teleport
in at least one place.sort
drawPolygonSequence
with 3 parameters, do not call sort
.customPolygon
drawPolygonSequence
with 3 parameters, call customPolygon
in at least one place.noTrace
drawPolygonSequence
with 3 parameters, call noTrace
in at least one place.showPicture
drawPolygonSequence
with 3 parameters, call showPicture
in at least one place.return
statement
drawPolygonSequence
with 3 parameters, do not use return _
.