Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Introduction to Python Programming

Exam Date: 06/13/2024


Name:______________________ Surname:________________________ ID:_________________
(Time allowed for completion is 1 hour)
(Please set your phone to silent mode or turn it off before starting)

Multiple Choice Questions (1-5)

Each question is worth 5 points, for a total of 25 points.

1. Which of the following methods is correct for finding the first position of a character or a
substring within a string in Python?

A) find()
B) index()
C) search()
D) locate()

2. How can a list containing the numbers 1 to 5 be created in Python?

A) [1, 2, 3, 4, 5]
B) (1, 2, 3, 4, 5)
C) {1, 2, 3, 4, 5}
D) 1, 2, 3, 4, 5

3. How can it be checked whether a number is odd or even in Python?

A) Using the % operator


B) Using the even() function
C) Using the check() method
D) Using the // operator

4. How can the number of elements in a list be printed in Python?


A) print(length(list))
B) print(count(list))
C) print(size(list))
D) print(len(list))
5. Which method is used to add an element to the end of a list in Python?
A) add()
B) append()
C) insert()
D) extend()

Read the Code and Report the Output (Questions 7-9)

Each question is worth 10 points, for a total of 30 points.

6. What will be displayed in the Console if the following code is executed?

numbers = [1, 2, 3, 4, 5]
s = [x**2 for x in numbers if x % 2 == 0]
print(s)

7. What will be displayed in the Console if the following code is executed?

a = [1, 3, 5]
b = [2, 4, 6]
c=a+b
print(c)
c.sort()
print(c)

8. What will be displayed in the Console if the following code is executed?

i=5
while True:
if i == 8:
Break
print(i)
i += 1
Coding Questions (2 * 25p)

9. Implement a linear search algorithm using the While command in Python (25p)

10. Calculate the common elements for two given lists as parameters in a function where the
result should not be sorted. (25p)

Example: Inputs: l1 = [5,2,4,9,99,100,3], l2 = [3, 5, 50,20,4,9,990,10]

Output: O = [5, 3, 4, 9]

You might also like