1/285
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a function in Python?
A reusable block of code designed to perform a specific task.
What is the basic purpose of print()?
print() displays information on the screen.
Write the code to print hello, world
print("hello, world")
What is a side effect?
When a function changes or affects something outside of itself, like print() displaying text on the screen.
Why does print("hello") have a side effect?
because it outputs text/string to the terminal.
What does it mean to call a function?
To run or use the function by writing its name followed by parentheses.
What is wrong with writing print without parentheses?
it does not call the function
Write the code to call the print function with no arguments
print()
What are parentheses used for when calling a function?
They tell Python to run the function.
What is an argument?
The information or value you give to a function.
In print("hello, world"), what is the argument?
"hello, world"
What is the general structure for calling a function with an argument?
function(argument)
In print("hello, world"), what is the function?
In print("hello, world"), what is the argument?
"hello, world"
What do quotation marks tell Python?
They tell Python that the content is text, also called a string.
What is a string?
Text surrounded by quotation marks.
What is the Python type name for a string?
str
Give an example of a string
"hello"
Can strings use single quotes?
Yes, for example 'hello'
Can strings use double quotes?
Yes, for example "hello"
Write code to print the string Saihaj
print("Saihaj")
What happens when Python runs print("hello, world")?
Python calls print(), reads the string argument, and displays hello, world.
What is the output of print("hello, world")?
hello, world
Do words/text need quotation marks in Python?
Yes, text needs quotation marks so Python treats it as a string.
Write code to print the string hello
print("hello")
Why would print(hello) cause an error if hello was never defined?
Because Python thinks hello is a variable name, not text.
Do numbers need quotation marks in Python?
No, numbers can be written directly.
Write code to print the number 5
print(5)
What is the difference between 5 and "5"?
5 is treated as an integer, while "5" is treated text/a string
What is the output of print(5 + 5)?
10
What is the output of print("5" + "5")?
55
Why does print("5" + "5") output 55 instead of 10?
Because Python joins the two strings instead of doing math.
How do you give print() multiple arguments?
Separate the arguments with commas.
Write code to print hello and world as two separate arguments
print("hello", "world")
What is the output of print("hello", "world")?
hello world
Write code to print Age: and 18 as separate arguments
print("Age:", 18)
What is the output of print("Age:", 18)?
Age: 18
Can variables be used as arguments?
Yes, variables can be passed into functions as arguments.
Write code that stores "Saihaj" in a variable called name
name = "Saihaj"
Write code that stores 18 in a variable called age
age = 18
Write code to print the value stored in name
print(name)
Write code to print My name is and then the variable name
print("My name is", name)
What are the three main types of print arguments from the notes?
String arguments, integer arguments, and variable arguments.
What is a bug?
A defect or error in a computer program caused by a mistake in the code.
What is debugging?
Finding and correcting errors in code.
What does the terminal command python hello.py do?
It uses Python to run the file named hello.py.
What does python mean in the command python hello.py?
It tells the terminal to use the Python program.
What does hello.py mean in the command python hello.py?
It is the Python file you want to run.
What does the .py file ending mean?
It means the file is a Python file.
Write the correct terminal command to run hello.py
python hello.py
If hello.py contains print("hello, world"), what appears after running python hello.py?
hello, world
What does input() do?
It shows a prompt, waits for the user to type something, and returns what the user typed.
Write code to ask the user What is your name?
input("What is your name? ")
What is a prompt in input()?
The message shown to the user inside input().
In input("Enter your age: "), what is the prompt?
"Enter your age: "
What is a variable?
A name that stores a value so you can use it later.
In name = "Saihaj", what is the variable name?
name
In name = "Saihaj", what is the value?
"Saihaj"
What does = mean in Python?
It is the assignment operator, meaning assign the value on the right to the variable on the left.
What is the assignment operator?
=
Write code to store "Hello" in a variable called hello
hello = "Hello"
Write code to store "Saihaj" in a variable called name
name = "Saihaj"
Write code to print hello and name as two variables
print(hello, name)
If hello = "Hello" and name = "Saihaj", what is the output of print(hello, name)?
Hello Saihaj
What is a comment?
A note in code that Python ignores.
What symbol creates a single-line comment in Python?
#
Write a comment that says This prints a greeting
Does Python run comments?
No, Python ignores comments.
Why are comments useful?
They explain what the code does for humans reading it.
Write code with a comment after it that stores the user's name
name = "Saihaj" # stores the user's name
Write code with a comment after it that prints name
print(name) # prints the value of name
What are triple quotes sometimes used for?
Longer notes or multi-line comments, though # is more common for regular comments.
Write a triple-quoted note
"""This is a longer note."""
What is pseudocode?
A way to plan code using normal language instead of real Python syntax.
Is pseudocode meant to be run by Python?
No, it is meant to help you plan the program.
Why is pseudocode useful?
It helps you think through the steps before writing real code.
Write pseudocode for asking the user for their name
Write pseudocode for storing a name in a variable
Write pseudocode for printing a greeting
What are parameters?
The options or variables listed in a function definition or documentation.
What does objects mean in print(*objects, sep=' ', end='\n', file=None, flush=False)?
The things you want to print.
What does the * in *objects mean?
It means print() can accept more than one object.
What does sep mean in print()?
Separator; it controls what goes between multiple printed objects.
What is the default sep value in print()?
A space.
What is the output of print("Hello", "Saihaj")?
Hello Saihaj
Write code to print Hello and Saihaj with a dash between them
print("Hello", "Saihaj", sep="-")
What is the output of print("Hello", "Saihaj", sep="-")?
Hello-Saihaj
What does end mean in print()?
It controls what happens at the end of the printed line.
What is the default end value in print()?
\n, which means new line.
What does \n mean?
New line.
What is the output of print("Hello") followed by print("World") on the next line?
Hello and World appear on separate lines.
Write code so Hello and World print on the same line with a space between them
print("Hello", end=" "); print("World")
What does file=None control in print()?
Where the output goes; by default, it prints to the screen.
What does flush=False control in print()?
Whether Python immediately forces the output to appear.
Do most beginner programs need to change file or flush?
No.
What is an escape character?
A backslash sequence that lets you put special characters inside a string.
What symbol starts an escape character?
What does \n do inside a string?
Creates a new line.
Write code to print Hello and World on separate lines using \n
print("Hello\nWorld")
What does \t do inside a string?
Creates a tab space.