1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Multiline string
A single string that contains several lines of text, usually created with triple quotation marks.
What are the two types of cells in Google Colab?
.Code cells contain executable Python code. Text cells contain explanations and documentation.
How do you execute a code cell without clicking the play button?
Press Ctrl + Enter.
What punctuation must follow print in Python
Parentheses: print()
What is the difference between these?
Python
print(23 + 5)
print("23 + 5")
The first displays 28 because Python evaluates it. The second displays 23 + 5 because quotation marks make it literal text.
What is a variable?
A name representing a place in memory where a value is stored.
What symbol assigns a value to a variable?
The equal sign, =.
: What is the difference between these?
print(my_variable)
print("my_variable")
The first displays the variableās value. The second displays the literal text my_variable.
What is a string?
A piece of text placed inside quotation marks.
What is an integer?
A whole number without a decimal point.
What is a float?
A number with a decimal point, such as 30.5.
What is an f-string?
A formatted string that combines text with variables, numbers, or calculations.
How do you create an f-string?
Put f before the opening quotation mark and put variables inside curly braces { }.
Python
1
print(f"The year is {year}.")
Given item = "book" and price = 20, write a line that displays āThe price of the book is 20.ā
print(f"The price of the {item} is {price}.")
What data type does input() always return?
A string, even when the user enters a number.
What is typecasting?
Converting a value from one data type to
Which functions convert input into numbers?
int() converts to a whole number. float() converts to a decimal number.
What does NameError mean?
A variable is undefined, misspelled, incorrectly capitalized, or has not been recreated after the runtime restarted.
What happens here?print(hello)
Python treats hello as a variable. If it has not been defined, it produces a NameError.
What does TypeError mean?
An operation uses incompatible data types, such as adding an integer to a string.
Why does this cause a TypeError?
Python
1
year = 1813
2
print("The year is " + year)
"The year is " is a string, but year is an integer. Direct concatenation requires two strings.
What does ValueError mean?
Python cannot convert a value into the requested type, such as converting "hello" with int().
Why does int("1.5") produce a ValueError?
1.5 is a decimal value, not a valid whole-number string. Use float() instead.
What are the three important errors to distinguish?
NameError: undefined or misspelled variable
TypeError: incompatible data types
ValueError: unsuitable value for conversion
What does the input() function do?
It pauses the program, waits for the user to type something, and returns the answer as a string.
What is a prompt?
A message inside input() telling the user what to enter.
Python
1
input("Please enter your age: ")
If the user enters 5 and 10 without typecasting, what does number_one + number_two produce?
510, because the two input strings are concatenated.
Why does the following code produce an error?
Python
1
number_one = int(input("Enter a number: "))
2
number_two = input("Enter another number: ")
3
print(number_one + number_two)
number_one is an integer, but number_two is a string. Adding them causes a TypeError.
How do you correctly receive a whole number?
number = int(input("Enter a number: "))
How do you correctly receive a decimal number?
number = float(input("Enter a number: "))
What is the difference between immediate and later typecasting?
Immediate typecasting converts input when it is entered. Later typecasting preserves the original string and converts it only when needed.
Why might you preserve "001" as a string?
Converting it to an integer changes it to 1 and removes the leading zeros. This matters for student IDs and reference numbers.
How do you separate multiple items inside print()?
Use commas.
Python
1
print("Total:", 20)
What does Python automatically add between comma-separated items?
One space.
How do you remove the automatic space?
Use sep="".
Python
1
print("Total: ", 20, sep="")
What is string concatenation?
Joining strings using +.
What happens when a string is multiplied by an integer?
The string is repeated.
Python
1
"-" * 5
What do these special characters do?
\n: new line
\t: tab position
\\: print a backslash
Why does the first code execution take longer?
Google must start and connect a temporary Python runtime.
Can a variable created in one code cell be used in another?
Yes, if the first cell was executed and the same runtime remains active.
What happens to variables when Colab terminates the runtime?
Their values disappear from memory, but the notebook and code remain saved.
How can you fix a NameError caused by a restarted runtime?
Select Run all to execute the cells from the beginning and recreate the variables.
What is literate programming?
Combining human-readable explanations with executable code in one document.
How does Colab support literate programming?
Text cells explain and document the program, while code cells contain executable instructions.
What is the main difference between Colabās free and paid versions?
The paid version offers more resources and longer runtimes. The free version is sufficient for this course.