Python Programming Exam
Total Marks: 50
Section A – Multiple Choice Questions (Theory)
Choose the correct option. (10 × 1 = 10 marks)
1. 1. What is the output of the following code?
x = [1, 2, 3]
print(x[::-1])
a) [1, 2, 3]
b) [3, 2, 1]
c) [1, 3, 2]
d) Syntax Error
2. 2. What is the correct way to declare an array in Python using the array module?
a) arr = array.array([1, 2, 3])
b) arr = array('i', [1, 2, 3])
c) arr = [1, 2, 3]
d) arr = array.array('int', [1, 2, 3])
3. 3. What will be the output of:
s = "Python"
print(s[2:5])
a) tho
b) yth
c) tho
d) tho
4. 4. Which of the following is not a valid loop structure in Python?
a) for
b) while
c) do-while
d) nested for
5. 5. What is the result of this expression: "Hello" + "World"?
a) Hello World
b) HelloWorld
c) Error
d) Hello + World
6. 6. Which function is used to get the length of a string?
a) length()
b) count()
c) size()
d) len()
7. 7. What is the output of the following slicing operation?
a = "abcdef"
print(a[::2])
a) abcdef
b) ace
c) bdf
d) af
8. 8. What does arr[-1] return in Python for an array?
a) First element
b) Error
c) Last element
d) Second element
9. 9. What is the result of 5 // 2 in Python?
a) 2.5
b) 3
c) 2
d) Error
10. 10. Which keyword is used to skip the current iteration in a loop?
a) skip
b) break
c) exit
d) continue
Section B – Coding Questions
(40 × 10 = 40 marks)
11. Q1. Basic Input/Output:
Write a Python program to:
- Take user input for a number and print whether it is even or odd.
Q2. For Loop:
Write a program using a `for` loop to:
- Print the sum of all numbers from 1 to N (take N as input).
12. Q3. Pattern Printing:
Print the following pattern for input `n = 5`:
1
12
123
1234
12345
Q4. Advanced Pattern:
Print the following pattern for `n = 4`:
*
**
***
****
13. Q5. Array Problem:
Using the `array` module:
- Create an array of integers and print the square of each element.
14. Q6. String Problem:
Write a Python function that:
- Takes a string input from the user and prints the number of vowels and consonants.
15. Q7. Slicing & Indexing:
Given a string input from the user:
- Print the string in reverse using slicing.
- Print every 2nd character of the string using slicing.
16. Q8. Array Indexing:
Create a list of integers from 1 to 10.
- Print elements from index 2 to 6.
- Replace the element at index 4 with 100 and print the updated list.