1/54
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
A literal is data which has a fixed value within itself.
What is a literal?
Because 2 is a literal, while hello is treated as a variable name.
Why does print(hello) give an error but print(2) does not?
A literal can be placed inside the parentheses.
What can be placed inside the parentheses of print() to produce an output?
Because Python stores and treats different types of literals differently.
Why are different types of literals treated differently in Python?
Integers, floating-point numbers, strings, and Boolean values.
What are the four types of literals covered in Lab 2?
A whole number, both positive and negative, including 0.
What is an integer?
Underscores can be used to improve readability of very large numbers without changing the value.
How can underscores be used with large integers?
It represents the integer 11111.
What does 11_111 represent?
Put a minus (-) sign before the number.
How do you indicate a negative integer in Python?
No. A positive sign is not necessary, although it can be used.
Is a positive sign required for a positive number?
Only 0 and 1.
What digits are used in binary numbers?
Write 0b or 0B, followed by the binary value.
What is the Python syntax for a binary number?
Numbers from 0 to 7.
What numbers can be used in an octal number?
Write 0o or 0O, followed by the octal value.
What is the Python syntax for an octal number?
0–9 and A–F.
What characters can be used in hexadecimal numbers?
Write 0x or 0X, followed by the hexadecimal value.
What is the Python syntax for a hexadecimal number?
Manual conversions.
What should you study regarding binary, octal, and hexadecimal for quizzes/exams?
A number which has a decimal point.
What is a floating-point number?
4.0
What does Python output for 4.?
0.7
What does Python output for .7?
e or E.
What letter is used for scientific notation in Python?
It represents the exponent.
What does the e represent in scientific notation?
Put a minus (-) sign before the exponent value.
How do you write a negative exponent in scientific notation?
6.637e+34
What is the output of print(6.637e34)?
Text enclosed in inverted commas.
What is a string?
True and False.
What are the two Boolean values?
True = 1 and False = 0.
What numerical values are associated with True and False?
They are reserved keywords.
What are True and False classified as in Python?
The output is a floating-point number.
What happens when an integer and a floating-point number are added?
A unary operation involves one number, while a binary operation involves two numbers.
What is the difference between a unary and binary operator?
Unary.
Is -5 unary or binary?
Binary.
Is 5 - 3 unary or binary?
The output will be a floating point.
What happens when at least one input is a floating point for addition, subtraction, or multiplication?
A floating-point number.
What type of output does / always produce?
//
What operator is used for integer/floor division?
Because // is floor division, which gives the lower value.
Why does 6 // 4 equal 1 instead of 2?
It gives 1, because it takes the lower value.
What does floor division do with 1.999?
A float.
If at least one input is a float in floor division, what type is the answer?
Because floor division takes the value toward negative infinity, and -2 is lower than -1.
Why does -6 // 4 equal -2?
The remainder after division.
What does the modulus operator return?
No. It calculates the remainder.
Does % calculate percentages?
3.0
What is 12 % 4.5?
The result will be a float.
What happens if at least one input to % is a float?
( ) → ** → unary + - → / // * % → binary + -
What is the order of operator precedence covered in Lab 2?
Left-side binding.
Do operators normally have left-side or right-side binding?
Exponentiation (**).
Which operator is the exception and starts from the right?
From the right, so it is 2 ** (2 ** 3).
How is 2 ** 2 ** 3 evaluated?
-9
What is the result of print(-3 ** 2)?
Because exponentiation has higher priority than the unary minus, so 3 ** 2 is calculated first, then the negative sign is applied.
Why is print(-3 ** 2) equal to -9 and not 9?
A value that can change and is used for storing data.
What is a variable?
variable_name = variable
What is the general syntax for creating a variable?
A variable can store any type of data/literal, including strings and integers.
What types of data can a variable store?
var = 1
var = var + 1
The existing variable is increased by 1, so var becomes 2.
What happens in this code?
Can contain letters (A-Z)
Can contain numbers (0-9)
Can contain underscores (_)
Cannot contain spaces or other special characters
Cannot use reserved keywords
Cannot start with a number
Should preferably start with a letter
What are the rules for naming variables in Python?
You have to declare it (X = Y).
What’s the first step in creating a variable?