26 May 2025 Python Foundations Question Bank
26 May 2025 Python Foundations Question Bank
Topics Covered: 1. Python Basics 2. Conditional Statements 3. Loops 4. Lists 5. Tuples 6. Dictionaries 7.
Strings 8. Functions
2. Which data type stores whole numbers? A. float B. str C. int D. bool
x = 5 / 2
Conditional Statements
1. Which keyword starts a condition in Python? A. condition B. loop C. if D. check
2. Which keyword is used for another condition after if? A. otherwise B. elseif C. elif D. nextif
3. Which keyword executes when all conditions are false? A. else B. stop C. endif D. none
x = 5
if x > 3:
print("Yes")
1
2. Which logical operator requires both conditions to be true? A. or B. and C. not D. xor
Loops
1. Which loop repeats while a condition is true? A. for B. while C. repeat D. loop
2. Which function commonly works with for loops? A. list() B. range() C. int() D. float()
for i in range(3):
print(i)
A. 1 2 3 B. 0 1 2 C. 0 1 2 3 D. 1 2
1. Which statement skips the current iteration? A. stop B. break C. continue D. pass
3. Infinite loops are mostly caused by: A. missing variables B. missing print() C. conditions never
becoming false D. syntax errors
Lists
1. Which brackets define a list? A. () B. {} C. [] D. <>
3. Which method removes the last item? A. remove() B. delete() C. pop() D. clear()
numbers = [1,2,3]
print(numbers[1])
A. 1 B. 2 C. 3 D. Error
Tuples
1. Which brackets define a tuple? A. [] B. {} C. () D. <>
2
3. What is the output?
t = (1,2,3)
print(t[0])
A. 1 B. 2 C. 3 D. Error
2. Which statement about tuples is true? A. They can grow automatically B. They are mutable C.
They are ordered D. They use curly braces
Dictionaries
1. Dictionaries store data as: A. indexes only B. key-value pairs C. rows only D. numbers only
student = {"name":"Sam"}
print(student["name"])
Strings
1. Strings are enclosed in: A. quotes B. brackets C. braces D. commas
3. Which method removes spaces at both ends? A. trim() B. strip() C. remove() D. clean()
text = "Python"
print(len(text))
3
A. 5 B. 6 C. 7 D. Error
Functions
1. Which keyword defines a function? A. function B. define C. fun D. def
def greet():
print("Hello")
greet()
1. A function parameter is: A. returned value B. input to a function C. output D. variable outside
function
2. Which keyword returns a value from a function? A. send B. output C. return D. print
4. Which statement calls a function? A. call greet B. greet[] C. greet() D. function greet
5. What is the scope of a local variable? A. entire program B. internet C. only inside function D. all
files
6. Which of the following is true about functions? A. They cannot return values B. They reduce code
reuse C. They improve organization D. They are only for math
4
11. Define loop.
12. Define for loop.
13. Define while loop.
14. Define iteration.
15. Define infinite loop.
16. Define list.
17. Define tuple.
18. Define dictionary.
19. Define key-value pair.
20. Define indexing.
21. Define slicing.
22. Define string.
23. Define function.
24. Define parameter.
25. Define argument.
26. Define return value.
27. Define local variable.
28. Define modular programming.
29. Define mutable object.
30. Define immutable object.
print(5 + 3)
2.
x = 10
print(x)
3.
print("Python")
4.
print(10 // 3)
5.
5
print(2 ** 3)
6.
x = 5
if x > 2:
print("Yes")
7.
x = 1
if x > 5:
print("A")
else:
print("B")
8.
for i in range(3):
print(i)
9.
count = 0
while count < 3:
print(count)
count += 1
10.
numbers = [1,2,3]
print(numbers[2])
11.
numbers = [1,2]
[Link](3)
print(numbers)
12.
6
print(len([1,2,3,4]))
13.
t = (10,20)
print(t[1])
14.
student = {"name":"John"}
print(student["name"])
15.
print("Hello".upper())
16.
print("PYTHON".lower())
17.
print(len("Computer"))
18.
print("Py" + "thon")
19.
def add(a,b):
return a+b
print(add(2,3))
20.
def greet():
print("Hi")
7
greet()
21.
for i in range(1,4):
print(i * 2)
22.
x = [1,2,3]
[Link]()
print(x)
23.
print(10 % 3)
24.
print(5 == 5)
25.
print(5 != 3)
26.
x = "Python"
print(x[0])
27.
print("abc" * 2)
28.
numbers = [5,1,3]
[Link]()
print(numbers)
8
29.
d = {"a":1,"b":2}
print([Link]())
30.
def square(x):
return x*x
print(square(4))
9
33. Write a program to merge two lists.
34. Write a program to rotate a list left.
35. Write a program to rotate a list right.
36. Write a program to find second largest number in a list.
37. Write a program to check if an element exists in a list.
38. Write a program to create a tuple.
39. Write a program to access tuple elements.
40. Write a program to convert tuple to list.
41. Write a program to count tuple elements.
42. Write a program to create a dictionary.
43. Write a program to display dictionary keys.
44. Write a program to display dictionary values.
45. Write a program to update dictionary values.
46. Write a program to merge dictionaries.
47. Write a program to count characters using a dictionary.
48. Write a program to count word frequency.
49. Write a program to invert a dictionary.
50. Write a program to find the key with maximum value.
51. Write a program to count vowels in a string.
52. Write a program to count consonants.
53. Write a program to reverse a string.
54. Write a program to check string palindrome.
55. Write a program to convert string to uppercase.
56. Write a program to convert string to lowercase.
57. Write a program to remove spaces from a string.
58. Write a program to replace vowels with *.
59. Write a program to count uppercase letters.
60. Write a program to count lowercase letters.
61. Write a program to check if two strings are anagrams.
62. Write a program to find the longest word.
63. Write a function to add two numbers.
64. Write a function to subtract two numbers.
65. Write a function to multiply two numbers.
66. Write a function to divide two numbers.
67. Write a function to calculate factorial.
68. Write a recursive factorial function.
69. Write a function to check prime numbers.
70. Write a function to find maximum in a list.
71. Write a function to count vowels.
72. Write a function to reverse a string.
73. Write a function to calculate square.
74. Write a function to calculate cube.
75. Write a function to display multiplication table.
76. Write a program using nested loops to print a square star pattern.
77. Write a program to print a pyramid pattern.
78. Write a program to print Floyd’s triangle.
79. Write a program to print Pascal’s triangle.
80. Write a program to generate random numbers.
81. Write a number guessing game.
82. Write a calculator program.
83. Write a menu-driven program.
10
84. Write a program to validate integer input.
85. Write a program to repeatedly ask for input until valid.
86. Write a program to prevent division by zero.
87. Write a program to create a list of squares.
88. Write a program to create a list of cubes.
89. Write a program using list comprehension.
90. Write a program to flatten nested lists.
91. Write a program to sum elements at even indices.
92. Write a program to sum elements at odd indices.
93. Write a program to count positive and negative numbers.
94. Write a program to split a list into halves.
95. Write a program to check whether a list is empty.
96. Write a program to concatenate strings.
97. Write a program to calculate average marks.
98. Write a program to store student data in a dictionary.
99. Write a function that returns the smallest number in a list.
100. Write a function that returns the second smallest number in a list.
11
30. continue skips an iteration.
31. Dictionaries cannot have duplicate keys.
32. Lists can store mixed data types.
33. Tuples can contain lists.
34. Strings can be concatenated.
35. upper() converts text to uppercase.
36. lower() converts text to lowercase.
37. strip() removes spaces at both ends.
38. Python supports recursion.
39. Functions can call other functions.
40. A function can return multiple values.
41. range() produces sequences.
42. Lists are ordered collections.
43. Dictionaries are unordered in older Python versions.
44. Python supports nested loops.
45. A loop can exist inside another loop.
46. if statements execute conditions.
47. elif means “else if”.
48. Comments are ignored by Python.
49. Strings are enclosed in quotes.
50. Python is an interpreted language.
12