HCC_Sample_Test (1) (1)
HCC_Sample_Test (1) (1)
Name:
Student ID:
x = 5
y = "10"
print(x * y)
(a) 15
(b) 5 + 10
(c) 1010101010
(d) None of the above
x = "15"
y = "20"
print(x + y)
(a) 15
Data Processing Using Python Midterm Page 2 of 9
(b) 1520
(c) 15 20
(d) None of the above
x = 5
y = "5"
print(int(x) == y)
(a) True
(b) False
(c) None of the above
8. Given the list ”my list = [1, 2, 3, 4, 5]”, what will be the output of ”print(my list[1:4])”?
(a) [2, 3, 4]
(b) [1, 2, 3]
(c) [2, 3, 4, 5]
(d) [3, 4, 5]
9. What will be the output of the following code?
(a) KeyError
(b) [’1’, ’2’]
(c) ’Key not found’
(d) None of the above
10. Given the tuple ‘my tuple = (1, 2, 3, 4, 5)‘, what will be the result of ‘my tuple[2]‘?
(a) 1
(b) 2
(c) 3
(d) None of the above
11. What will be the output of the following code?
(a) yoPgmn
(b) hnPormig
(c) to rgamn
(d) toPormig
Cont.
Data Processing Using Python Midterm Page 3 of 9
my_list = (1, 2, 3, 4)
my_list[1] = 5
my_list[-2] = 6
print(my_list)
(a) (1, 5, 3, 4)
(b) (1, 5, 6, 4)
(c) (1, 2, 3, 4)
(d) None of the above
my_list = [1, 2, 3, 4, 5]
my_list.append(6)
print(my_list)
(a) [1, 2, 3, 4, 5]
(b) [1, 2, 3, 4, 5, 6]
(c) [1, 2, 3, 4, 6]
(d) [6, 1, 2, 3, 4, 5]
my_tuple = (1, 2, 3, 4, 5)
my_tuple = my_tuple + (6,)
print(my_tuple)
(a) (1, 2, 3, 4, 5, 6)
(b) (1, 2, 3, 4, 6)
(c) (6, 1, 2, 3, 4, 5)
(d) None of the above
my_string = "hello"
my_string[0].upper()
print(my_string)
(a) HELLO
(b) hello
(c) Hello
Cont.
Data Processing Using Python Midterm Page 4 of 9
my_list = [1, 2, 3]
my_list.extend([4, 5])
print(my_list)
(a) [1, 2, 3]
(b) [1, 2, 3, 4, 5]
(c) [4, 5, 1, 2, 3]
(d) [1, 2, 3, [4, 5]]
result = add(3, 4)
print(result)
(a) 7
(b) 34
(c) 12
(d) None of the above
numbers = [1, 2, 3, 4, 5]
print(numbers[2])
(a) 1
(b) 2
(c) 3
(d) 4
a = [1, 2, 3]
b = a
b.append(4)
print(a)
Cont.
Data Processing Using Python Midterm Page 5 of 9
(a) [1, 2, 3]
(b) [1, 2, 3, 4]
(c) [4, 1, 2, 3]
(d) None of the above
for i in range(5):
print(i)
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)
print(factorial(4))
(a) 4
(b) 12
(c) 24
(d) None of the above
print(func(1))
print(func(2))
(a) [1]
(b) [2]
(c) [1, 2]
(d) [2, 1]
25. Consider the following code snippet. What will be the output?
def outer_func(a):
def inner_func(b):
return a + b
return inner_func
add_five = outer_func(5)
print(add_five(10))
Cont.
Data Processing Using Python Midterm Page 6 of 9
(a) 5
(b) 10
(c) 15
(d) None of the above
x = [1, 2, 3, 4]
y = x
y.append(5)
print(x)
(a) [1, 2, 3, 4]
(b) [1, 2, 3, 4, 5]
(c) [5]
(d) None of the above
def my_func(lst):
lst = [0] * len(lst)
my_list = [1, 2, 3]
my_func(my_list)
print(my_list)
(a) [0, 0, 0]
(b) [1, 2, 3]
(c) []
(d) None of the above
x = [1, 2, 3]
y = x[:]
y[0] = 0
print(x)
print(y)
29. What are the values of x and y after the following code is executed?
x = 5
y = 10
if x > 5:
y = 20
print(x, y)
(a) 5, 10
Cont.
Data Processing Using Python Midterm Page 7 of 9
(b) 5, 20
(c) 10, 20
(d) 10, 10
class MyClass:
def __init__(self, x):
self.x = x
obj = MyClass(5)
print(obj.x)
Cont.
Data Processing Using Python Midterm Page 8 of 9
(a) 5
(b) 0
(c) None
(d) Error
class MyClass:
def __init__(self, x):
self.x = x
obj_a = MyClass(5)
obj_b = MyClass(10)
if obj_a == obj_b:
print(’Equal’)
else:
print(’Not equal’)
(a) Equal
(b) Not equal
(c) Error
(d) None
class Person:
def __init__(self, name):
self.name = name
def action(self):
return self.name + ’ punches the air’
class Knight(Person):
def action(self):
return self.name + ’ swings a sword’
class Wizard(Person):
def action(self):
return self.name + ’ casts a spell’
p = Paladin(’Arthur’)
print(p.action())
Cont.
Data Processing Using Python Midterm Page 9 of 9
class A:
def __init__(self):
self.x = 1
class B(A):
def __init__(self):
super().__init__()
self.y = 2
obj = B()
print(obj.x, obj.y)
(a) 1, 2
(b) 2, 1
(c) 1, None
(d) 2, None
class A:
def __init__(self):
self.x = 1
class B(A):
def __init__(self):
super().__init__()
self.x = 2
obj = B()
print(obj.x)
(a) 1
(b) 2
(c) None
(d) Error
40. In Python, which built-in function is used to check if two objects are the same?
The End.