CMU CS Academy Unit 2.1 Exercises
and Solutions
2.1.3 Two Hexagons - answer def drawTwoHexagons(color):
# Create two hexagons. Use the function parameter for the fill of the
# top hexagon and the border of the bottom hexagon!
### Place Your Code Here ###
RegularPolygon(200, 100, 100, 6, fill=color)
RegularPolygon(200, 300, 100, 6, fill=None, border=color, borderWidth=8)
##### Place your code above this line, code below is for testing purposes #####
# test case:
drawTwoHexagons('green')
2.1.3 Polygon Flower - answer Rect(0, 0, 400, 400, fill='skyBlue')
def drawFlower(color):
# Change these shapes so they use the color parameter for the flower petals.
### Modify Your Code Here ###
RegularPolygon(200, 300, 30, 4, fill='green')
RegularPolygon(200, 340, 30, 4, fill='green')
RegularPolygon(200, 380, 30, 4, fill='green')
RegularPolygon(200, 200, 100, 4, fill=color)
RegularPolygon(200, 200, 50, 4, fill='sienna')
RegularPolygon(150, 150, 50, 4, fill=color)
RegularPolygon(150, 250, 50, 4, fill=color)
RegularPolygon(250, 150, 50, 4, fill=color)
RegularPolygon(250, 250, 50, 4, fill=color)
##### Place your code above this line, code below is for testing purposes #####
# test case:
drawFlower('gold')
2.1.3 3D Labels - answer Rect(0, 0, 400, 400, fill='aliceBlue')
def draw3DLabel(text):
# Draw two labels, one centered slightly to the right of the other.
### Place Your Code Here ###
Label(text, 205, 200, size=65, fill='darkGreen', font='arial', bold=True)
Label(text, 200, 200, size=65, fill='limeGreen', font='arial', bold=True)
##### Place your code above this line, code below is for testing purposes #####
# test case:
draw3DLabel('Hello World')
2.1.3 Cooking an Egg - answer Rect(0, 0, 400, 400, fill='goldenrod')
# pan
Line(105, 305, 0, 400, fill='dimGrey', lineWidth=40)
, Circle(200, 200, 145, fill=rgb(60, 60, 60), border='darkGrey', borderWidth=10)
Circle(200, 200, 135, fill=None,
border=gradient('black', 'black', 'black', 'dimGrey'), borderWidth=20)
def drawEgg(opacity):
# Draw the egg, using the opacity provided to the function.
### Place Your Code Here ###
Oval(230, 220, 100, 120, fill='white', opacity=opacity)
Circle(220, 220, 20, fill='gold', opacity=opacity)
##### Place your code above this line, code below is for testing purposes #####
# test case:
drawEgg(100)
2.1.3 Bunny With a Spot - answer def drawBunny(bunnyColor):
Rect(0, 0, 400, 400, fill=gradient('dodgerBlue', 'deepSkyBlue'))
# Change the ears below to use the parameter of the function as the fill.
### Fix Your Code Here ###
Oval(155, 110, 60, 170, fill=bunnyColor)
Oval(245, 110, 60, 170, fill=bunnyColor)
Oval(155, 115, 40, 140, fill=gradient('seashell', 'wheat', start='bottom'))
Oval(245, 115, 40, 140, fill=gradient('seashell', 'wheat', start='bottom'))
# head
Oval(200, 230, 200, 160, fill='white')
Circle(150, 300, 80, fill='white')
Circle(250, 300, 80, fill='white')
# nose
Polygon(180, 310, 220, 310, 200, 350)
# Draw the spot around the eye.
### Place Your Code Here ###
# eyes
Oval(250, 270, 60, 100, fill=bunnyColor)
Oval(150, 275, 30, 50)
Oval(150, 270, 10, 20, fill='white')
Oval(250, 275, 30, 50)
Oval(250, 270, 10, 20, fill='white')
##### Place your code above this line, code below is for testing purposes #####
# test case:
drawBunny('pink')
2.1.5 Inflating Balloon - answer Rect(0, 0, 400, 400, fill='skyBlue')
def drawBalloon(inflatedAmount, lightColor, darkColor):
# Update these shapes to use the parameters.
### Fix Your Code Here ###
RegularPolygon(200, 370, 20, 3, fill=darkColor)
Oval(200, 185, inflatedAmount, 340,
fill=gradient(lightColor, darkColor, start='right-top'))
##### Place your code above this line, code below is for testing purposes #####