CMU CS Academy Answer Key

CMU CS Academy Answer Key

CMU CS Academy answer keys are unofficial, community-compiled resources (often found on Reddit or Discord) designed to help students check their work, understand complex programming logic, and reinforce learning in Python-based, graphics-heavy curriculum. They cover units 1–5, including tasks on functions, shapes, and conditionals.

Category:

/ 10
CMU CS Academy
Complete Answer Key — Units 1–5 | 2024/2025 | 100% Verified
Comprehensive answer key and study guide for Carnegie Mellon University's CS Academy covering all key
concepts, vocabulary terms, code solutions, and quiz answers for Units 1–5. Topics include shapes & graphics,
functions & parameters, conditionals, events, variables, loops, and more.
# Unit / Topic # Unit / Topic
1 Unit 1 — Shapes, Canvas & Graphics 2 Unit 1 — Shape Properties & Colors
3 Unit 2 — Functions: Key Vocabulary 4 Unit 2 — Functions: Code Examples
5 Unit 2 — Mouse Events & onMousePress 6 Unit 3 — Conditionals (if/elif/else)
7 Unit 3 — Helper Functions 8 Unit 4 — Variables & Global State
9 Unit 4 — Boolean & Comparison Ops 10 Unit 5 — Loops (for loops)
11 Unit 5 — Groups & Looping Through 12 Code Exercise Solutions (2.1.3, etc.)
13 Naming Rules & Best Practices 14 Quick Reference — All Key Terms
Unit 1: Shapes, Canvas & Graphics
Q: What are the dimensions of the CMU CS Academy canvas?
The canvas is 400 × 400 pixels. The coordinate system starts at (0, 0) in the TOP-LEFT corner. X increases
to the RIGHT; Y increases DOWNWARD.
Shape / Function Syntax Key Parameters
Rectangle Rect(x, y, width, height) x/y = top-left corner; width & height in pixels
Circle Circle(cx, cy, radius) cx/cy = center point; radius
Oval Oval(cx, cy, width, height) cx/cy = center; width & height
Line Line(x1, y1, x2, y2) two endpoint coordinates
Polygon Polygon(x1,y1, x2,y2, ...) list of (x,y) vertex pairs
RegularPolygon RegularPolygon(cx,cy,radius,sides) center, radius, number of sides
Star Star(cx, cy, radius, points) center, outer radius, number of points
Label Label('text', cx, cy) text string, center x/y
Arc Arc(cx,cy,w,h,startAngle,sweepAngle) portion of an oval; angles in degrees
Arrow Arrow(x1,y1,x2,y2) line with arrowhead at endpoint 2
Image Image(url, cx, cy) image URL and center position
Unit 1: Shape Properties, Colors & Styling
Q: How do you set the fill color of a shape?
Use the fill= property. Example: Circle(200, 200, 50, fill='red')
You can use color names ('gold', 'skyBlue') or rgb() values.
# Named color
Circle(200, 200, 50, fill='tomato')
# RGB color (red=255, green=165, blue=0 = orange)
Rect(50, 50, 100, 60, fill=rgb(255, 165, 0))
Q: How do you add a border to a shape?
Use border= and borderWidth= properties.
Example: Rect(100, 100, 200, 100, fill='white', border='black', borderWidth=3)
Rect(50, 50, 300, 200, fill='skyBlue', border='navy', borderWidth=5)
Q: How do you make a shape partially transparent?
Use the opacity= property (value between 0 and 1).
opacity=1 is fully visible; opacity=0 is invisible.
Circle(200, 200, 100, fill='red', opacity=0.5) # 50% transparent
Q: How do you use gradient colors in CS Academy?
Use gradient() for two-color gradients.
Example: Rect(0, 0, 400, 400, fill=gradient('gold', 'orange', start='left'))
Q: How do you add a Label (text) to the canvas?
Label('text', x, y, size=20, fill='black', bold=True, italic=False)
x and y are the CENTER of the label.
Label('Hello World!', 200, 200, size=30, fill='navy', bold=True)
Q: What is the Inspector tool in CS Academy?
A tool that shows the properties (color, radius, size, position, etc.) of any shape when you hover over it on
the canvas. Useful for debugging layout.
Q: How do you specify colors using RGB values?
Use rgb(red, green, blue) where each value is 0–255.
rgb(255, 0, 0) = red | rgb(0, 255, 0) = green | rgb(0, 0, 255) = blue
rgb(255, 255, 255) = white | rgb(0, 0, 0) = black
Circle(200, 200, 80, fill=rgb(128, 0, 128)) # purple
Unit 2: Functions — Key Vocabulary & Definitions
Function
A key concept in programming that defines a body of code which:
• Can be called later to run the code in the body
• Can repeat this action multiple times
• Avoids code repetition (DRY principle — Don't Repeat Yourself)
Function Definition (def)
The code that creates a function using the 'def' keyword. Format:
def functionName(parameter1, parameter2):
# indented body goes here
Function Call
The place in your program where you USE (invoke) a function you have defined.
Example: drawStar(200, 200, 'gold') this calls the drawStar function
Function Parameter
A variable name in the function definition that receives the passed-in argument.
Example: def drawCircle(x, y, color): x, y, color are parameters
Function Argument
The actual values passed in when a function is called (matched to parameters).
Example: drawCircle(100, 200, 'red') 100, 200, 'red' are arguments
Function Name
A unique identifier given to the function when defined, and used whenever it is called.
Must follow legal naming rules. Good names use camelCase.
Function Body
The part of a function that contains the commands/instructions.
MUST be indented (one tab or 4 spaces). The body ends when indentation returns.
Function Indenting
The section under the function name, starting with a tab from the keyboard.
All lines inside the function body must be indented at the same level.
Hardcode
To put a specific value directly in a program instead of using a variable or parameter.
Example: Circle(200, 200, 50) 200, 200, 50 are hardcoded values.
Hardcoding is fine for fixed values, but parameters make code reusable.
camelCase
A naming convention where the first letter is lowercase and the first letter of each subsequent word is
uppercase.
Examples: drawBigCircle, myVariableName, onMousePress
Unit 2: Functions — Code Examples & Quiz Answers
Q: Write a function that draws a circle at any position and color.
def drawColorCircle(x, y, color):
Circle(x, y, 50, fill=color)
# Call the function:
drawColorCircle(200, 200, 'gold')
drawColorCircle(100, 100, 'blue')
def drawColorCircle(x, y, color):
Circle(x, y, 50, fill=color)
# Calling it multiple times:
drawColorCircle(200, 200, 'gold')
drawColorCircle(100, 300, 'tomato')
Q: For the function: def drawCompartment(x, y, color): — what are the parameters?
The parameters are: x, y, color
(Parameters are the variable names listed inside the parentheses of the def line.)
Q: For the call: drawCompartment(140, 105, 'red') — what are the arguments?
The arguments are: 140, 105, 'red'
(Arguments are the actual values passed into the function when it is called.)
Q: What is the function name in: def drawBigCircle(centerX, centerY, color)?
drawBigCircle
(The function name is the identifier that comes directly after the 'def' keyword.)
/ 10
Related