0% found this document useful (0 votes)
4 views

HCC_Sample_Test (1) (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

HCC_Sample_Test (1) (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Data Processing Using Python Midterm May 22, 2024

Name:

Student ID:

Circle the best answer. PLEASE READ THE QUESTIONS CAREFULLY.

1. Which of the following is not a valid data type in Python?


(a) int
(b) float
(c) string
(d) char
2. Which of the following command is used to check the data type of a variable?
(a) type()
(b) typeof()
(c) datatype()
(d) None of the above
3. Which of the following is not a valid variable name in Python?
(a) myVar
(b) my var
(c) my-var
(d) None of the above
4. Which of the following is not a valid way to create a string in Python?
(a) ”Hello”
(b) ’Hello’
(c) ”””Hello”””
(d) None of the above
5. What is the output of the following code?

x = 5
y = "10"
print(x * y)

(a) 15
(b) 5 + 10
(c) 1010101010
(d) None of the above

6. What is the output of the following code?

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

7. What is the output of the following code?

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?

my_dict = {’a’: ’1’, ’b’: ’2’, ’c’: ’3’}


print(my_dict.get(’a’+’b’, ’Key not found’))

(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?

my_string = "Python Programming"


print(my_string[3::2])

(a) yoPgmn
(b) hnPormig
(c) to rgamn
(d) toPormig

12. What will be the output of the following code?

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

13. What will be the output of the following code?

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]

14. What will be the output of the following code?

my_dict = {’a’: 1, ’b’: 2}


my_dict[’c’] = 3
print(my_dict)

(a) ’a’: 1, ’b’: 2


(b) ’a’: 1, ’b’: 2, ’c’: 3
(c) ’a’: 1, ’b’: 2, 3
(d) ’c’: 3, ’a’: 1, ’b’: 2

15. What will be the output of the following code?

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

16. What will be the output of the following code?

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

(d) None of the above

17. What will be the output of the following code?

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]]

18. What will be the output of the following code?

my_dict = {’a’: 1, ’b’: 2, ’c’: 3}


print(list(my_dict.keys()))

(a) [’a’, ’b’, ’c’]


(b) [’1’, ’2’, ’3’]
(c) [’a’, ’b’, ’c’, ’d’]
(d) [’keys’]

19. What is the output of the following code?

def add(a, b):


return a + b

result = add(3, 4)
print(result)

(a) 7
(b) 34
(c) 12
(d) None of the above

20. What will be the output of the following code?

numbers = [1, 2, 3, 4, 5]
print(numbers[2])

(a) 1
(b) 2
(c) 3
(d) 4

21. What will be the output of the following code?

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

22. What does the following code do?

for i in range(5):
print(i)

(a) Prints numbers 1 to 5


(b) Prints numbers 0 to 5
(c) Prints numbers 0 to 4
(d) Prints numbers 1 to 4

23. What is the output of the following code?

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

24. What is the output of the following code?

def func(x, y=[]):


y.append(x)
return y

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

26. What will be the output of the following code?

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

27. What does the following code print?

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

28. What will be the output of the following code?

x = [1, 2, 3]
y = x[:]
y[0] = 0
print(x)
print(y)

(a) [1, 2, 3] [0, 2, 3]


(b) [0, 2, 3] [0, 2, 3]
(c) [0, 2, 3] [1, 2, 3]
(d) None of the above

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

30. In Python, which of the following is not a valid comparison operator?


(a) ==
(b) !=
(c) ¡¿
(d) None of the above
31. What are branching statements in Python?
(a) if, else, elif
(b) for, while
(c) break, continue
(d) None of the above
32. Given a list of file names(files = [’file1.txt’, ’file2.txt’, ’file3.txt’]), how can you extract the file extension
from each file name?
(a) Use the split() method
(b) Use the join() method
(c) Use the append() method
(d) None of the above
33. We have a list of numbers (numbers = [1, 2, 3, 4, 5]). How can we calculate the sum of all the numbers
in the list?
(a) sum(numbers)
(b) numbers.sum()
(c) numbers.sum
(d) None of the above
34. What is the output of the following code?

files = [’1.txt’, ’14.txt’, ’2.txt’, ’11.txt’]


files.sort()
print(files)

(a) [’1.txt’, ’2.txt’, ’11.txt’, ’14.txt’]


(b) [’1.txt’, ’11.txt’, ’14.txt’, ’2.txt’]
(c) [’14.txt’, ’11.txt’, ’2.txt’, ’1.txt’]
(d) [’2.txt’, ’11.txt’, ’14.txt’, ’1.txt’]

35. What is the output of the following code?

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

36. What is the output of the following code?

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

37. What is the output of the following code?

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’

class Paladin(Knight, Wizard):


def do_something(self):
return self.name + ’ heals the wounded’

p = Paladin(’Arthur’)
print(p.action())

(a) Arthur punches the air


(b) Arthur swings a sword
(c) Arthur casts a spell
(d) Arthur heals the wounded

Cont.
Data Processing Using Python Midterm Page 9 of 9

38. What is the output of the following code?

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

39. What is the output of the following code?

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?

(a) obj. eq (other)


(b) obj. ne (other)
(c) obj. cmp (other)
(d) obj. is (other)

The End.

You might also like