Podcast
Questions and Answers
What is a common characteristic of good function names in Python?
What is a common characteristic of good function names in Python?
- They must contain at least one digit
- They are short and clear (correct)
- They must start with an uppercase letter
- They must be at least 10 characters long
What happens when you call a function with no parameters in Python?
What happens when you call a function with no parameters in Python?
- The function will not be executed
- You must pass a default value
- You still need to use parentheses (correct)
- You don't need to use parentheses
What is the purpose of the pass
statement in a function?
What is the purpose of the pass
statement in a function?
- To print a message to the console
- To tell Python to do nothing (correct)
- To raise an error
- To exit the function early
What is the rule for function names in Python regarding spaces?
What is the rule for function names in Python regarding spaces?
What is the purpose of the onMousePress
function in Python?
What is the purpose of the onMousePress
function in Python?
What is a requirement for function parameters and arguments in Python?
What is a requirement for function parameters and arguments in Python?
What is the purpose of using the onMouseRelease(mouseX, mouseY) event?
What is the purpose of using the onMouseRelease(mouseX, mouseY) event?
How do you add 10 to a shape's x-coordinate?
How do you add 10 to a shape's x-coordinate?
What is the default value of the border property for a shape?
What is the default value of the border property for a shape?
Which property determines the text of a Label shape?
Which property determines the text of a Label shape?
What is the purpose of top-level code?
What is the purpose of top-level code?
How do you set the background color of the app?
How do you set the background color of the app?
Flashcards are hidden until you start studying
Study Notes
Functions Basics
- A function's body should be indented by 4 spaces
- Function parameters can be of different types: numbers, strings, booleans
- Functions can be called multiple times
- Python has rules for legal function names: must start with letters, can contain digits, cannot contain spaces, newlines, or punctuation
- Good function names are short, clear, and camelCased
Function Parameters and Arguments
- Parameters and arguments must match in number and order
- When calling a function with no parameters, use parentheses
Mouse Events
- The onMousePress(mouseX, mouseY) function is called every time the canvas is clicked
- The function name must match the exact name
- Parameter names can be chosen freely, but represent the x and y coordinates of the mouse press on the canvas
Using and Debugging Events
- Use print to understand and debug code
- Print statements should be removed when no longer needed
- Use the control or ctrl key to access the inspector
Top-Level Code
- Any code not inside a function is top-level code
- Runs exactly once before any event is called
Math Operations
- Use + to add, - to subtract, * to multiply, / to divide
Globals
- To modify a shape after creation, store it in a global variable
- Get and set shape properties in any function
Mouse Release Events
- The onMouseRelease(mouseX, mouseY) function is called every time the mouse is released
- Often used to modify existing shapes
Shape Properties
- General shape properties include: position, size, alignment, fill, border, and more
- Properties can be gotten and set
- Default values are provided for each property
Shape-Specific Properties
- Circle: radius
- RegularPolygon: radius, points
- Star: radius, points, roundness
- Line: x1, y1, x2, y2, dashes, lineWidth
- Label: value, font, size, bold, italic
- App background: app.background
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.