"hello"
or 'hello'
3
3.14
True
or False
Use the function type()
with each literal type.
+
: plus
-
: minus
*
: multiple
/
: divide
**
: power
//
: divide and floor
%
: modulos
Think of the whiteboard as your program’s console. Write down what would display as the output for the following code:
What value will each of these variables take on? No computers!
a1 = 5 / 5 * 10 * 5 a2 = 5 / (5 * 10) * 5 b1 = 5 * 10 - 2 b2 = 5 * (10 - 2) c = (3 // (4 // 5)) + 1
a1 = 5 / 5 * 10 * 5
a2 = 5 / (5 * 10) * 5
b1 = 5 * 10 - 2
b2 = 5 * (10 - 2)
# c = (3 // (4 // 5)) + 1 ERROR -- Zero Division
print(a1)
print(a2)
print(b1)
print(b2)
50.0
0.5
48
40
Note that the division operator returns a float even when both numerator and denominator are integers
round()
round()
Use the round() function to get a floating-point number rounded to the specified number of decimals.
Syntax:
The number of digits (ndigits
) is optional, but we will often round number to two decimals:
round()
Run the following code on your laptop
Discuss with your partner how the output is calculated
round()
Use the round() function to get a floating-point number rounded to the specified number of decimals.
Syntax:
Rounding is done toward the nearest even choice:
Variable assignments are not like math — they can appear in equations that make no mathematical sense.
x = x + 2
means “take the current value of x, add it with 2, and assign the resulting value (7) to x as its new value.”
Write code to calculate the area of a circle when radius is 3:
You have 10 minutes to complete the quiz.
Comments
Comments are text that is meant to be read, but not executed. The purpose is to improve readability.