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?
What happens when you call a function with no parameters in Python?
What happens when you call a function with no parameters in Python?
What is the purpose of the pass
statement in a function?
What is the purpose of the pass
statement in a function?
What is the rule for function names in Python regarding spaces?
What is the rule for function names in Python regarding spaces?
Signup and view all the answers
What is the purpose of the onMousePress
function in Python?
What is the purpose of the onMousePress
function in Python?
Signup and view all the answers
What is a requirement for function parameters and arguments in Python?
What is a requirement for function parameters and arguments in Python?
Signup and view all the answers
What is the purpose of using the onMouseRelease(mouseX, mouseY) event?
What is the purpose of using the onMouseRelease(mouseX, mouseY) event?
Signup and view all the answers
How do you add 10 to a shape's x-coordinate?
How do you add 10 to a shape's x-coordinate?
Signup and view all the answers
What is the default value of the border property for a shape?
What is the default value of the border property for a shape?
Signup and view all the answers
Which property determines the text of a Label shape?
Which property determines the text of a Label shape?
Signup and view all the answers
What is the purpose of top-level code?
What is the purpose of top-level code?
Signup and view all the answers
How do you set the background color of the app?
How do you set the background color of the app?
Signup and view all the answers
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.
Description
Test your understanding of basic functions in Python, including function elements, parameter types, and naming conventions. Learn how to define and call a function in Python.