In: Computer Science
23. Given a = 5, b = 4, c = 2, evaluate the following:
a) a//c
b) a % b
c) b **c
d) b *= c
27. Given the following
var_1 = 2.0
var_2 = "apple"
var_3 = 'orange'
var_4 = 4
Predict the output of the following statements or indicate that there would be an error.
a) print (var_1)
b) print (var_2)
c) print ("var_3")
d) print (var_1 / var_4)
e) print (var_4 + var_3)
f) print (var_2 + var_3)
23. Given a = 5, b = 4, c = 2
(a)
a//c - Floor division or Integer division which returns the integer
without any decimal
5//2 = 2
(b) a % b - Returns the remainder when a is divided
by b
5%4 = 1
(c) b **c - Returns the result when b is raised to
the power of c
4**2 = 4^2 = 16
(d) b *= c - Returns the result when b is multiplied
by c and the result is stored back in b
b= b*c = 4*2 = 8
27. Given the following
var_1 = 2.0
var_2 = "apple"
var_3 = 'orange'
var_4 = 4
(a) print (var_1) - prints the value stored in
variable var_1 i.e 2.0
2.0
(b) print (var_2) - prints the value stored in
variable var_2 i.e "apple"
apple
(c) print ("var_3") - print the string "var_3"
var_3
(d) print (var_1 / var_4) - performs floating-point
divison and prints the result obtained when var_1 is divided by
var_4 i.e 2.0/4 = 0.5
0.5
(e) print (var_4 + var_3) - generates type error
since there is no "+" operator specified for operand types "int"
and "str"
TypeError: unsupported operand type(s) for +: 'int' and
'str'
(f) print (var_2 + var_3) - performs string
concatenation of var_2 and var_3 and prints the result of this
concatenation i.e "apple"+'orange' = appleorange
appleorange