ITE3711 Lab1.3 Operators
ITE3711 Lab1.3 Operators
Exercise 1
Write down the output of the program fragments below.
Example:
Program fragments Output
print(5 + 5) 10
print(5 - 5) 0
print(5 * 5) 25
(d print(7 % 3)
)
(e) print(2 ** 3)
(f) print(6 + 3 - 2)
(g print(5 * 4 + 2)
)
(h print(7 - 4 * 2)
)
(i) print(12 / 3 + 2 * 4)
(j) print(2 ** 3 + 1 * 2 + 4)
(k print(5 % 2 + 3 ** 2)
)
(l) print(10 * 2 // 4 - 1)
Exercise 1 (cont’)
Write down the output of the program fragments below.
num3 = 85
print(num1 + num2)
print(num1 * 2 - num3)
print(num2 % 2 + num2)
num2 = 49
num3 = 7
print(num2 + num1)
print(num2 / num3)
print(num2 // num3)
(o) num1 = 67
num2 = 98
num3 = 23
print((num1 // num3) ** 2)
print((num2 % 2 + 5) * num3)
Exercise 2
Write down the program code format of the following formulas.
Example:
Formula Python program code format
√ a2 +ab (a ** 2 + a * b) ** 0.5
2 r∗3.14
base∗height
2
y 2− y 1
x 2−x 1
Celsius∗9
+ 32
5
( b 1+b 2 ) h
2
( )
nt
r
P 1+
n
−b+ √ b 2−4 ac
2a
Exercise 3
Write down the output of the program fragments below.
Example:
Program fragments Output
(a) x = 5 6
x += 1
print(x)
(b x = 10
) x -= 4
print(x)
(c) x = 3
x *= 4
print(x)
(d x = 20
) x /= 5
print(x)
(e) x = 35
x %= 6
print(x)
(f) x = 65
x %= 9
x *= 5
print(x)
Exercise 4
Write down the output of the program fragments below.
Example:
Program fragments Output
num1 = 5 False
num2 = 25
(b num1 = 6
) num2 = 8
num3 = 48
print(msg1 == msg2)
print(msg2 != msg1)
Exercise 4 (cont’)
Write down the output of the program fragments below.
(e) num1 = 10
num2 = 5
msg1 = "hello"
msg2 = "world"