Font size
WorksheetsGeneral Knowledge Quiz
Total questions: 114
Worksheet time: 57mins
What will What is the output of the following code?
A. [1] and [2]
B. [1] and [1, 2]
C. [1, 2] and [1, 2]
D. [1] and [2]
3. What is the result of this lambda function?
10
12
Error
12
What will be the output of this python program?
10
15
Error
5
What is
101
220
Error
12
4. What will be the output of this Python program?
10
5
15
Error
What will
1
2
3
4
What is
101
220
Error
12
What will
10
5
15
Error
What will
1
2
3
4
1. What will be the output of the following code?
A) [1] [2] [3] [4]
B) [1] [1, 2] [3] [1, 2, 4]
C) [1] [2] [3] [4]
D) [1] [1, 2] [3] [1, 2, 4]
10. What will happen if this function is called with sum_numbers(5)?
A) 5
B) 15
C) Error
D) 10
9. What does this JSON operation do?
A) Alice
B) Error
C) '{"name": "Alice", "age": 25}'
D) None
1. What will be the output of the following code?
A) [1] [2] [3] [4]
B) [1] [1, 2] [3] [1, 2, 4]
C) [1] [2] [3] [4]
D) [1] [1, 2] [3] [1, 2, 4]
2. What does the following Python snippet output?
A) False False False
B) True True True
C) False True False
D) True False True
3. What is the result of this lambda function?
A) 10
B) 12
C) 20
D) Error
4. What will be the output of this Python program?
A) 10
B) 5
C) 15
D) Error
5. What does the following code do?
A) [1, 4, 9, 16, 25]
B) [0, 1, 4, 9, 16]
C) [0, 1, 2, 3, 4]
D) Error
6. What is the output of this code?
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) Error
D) None
7. What does this regex pattern match?
A) 123-456-7890
B) 123-456
C) Error
D) None
8. What will the following code output?
A) 1 2 (3, 4) {'x': 5, 'y': 6}
B) 1 2 3 4 x=5 y=6
C) (1, 2) (3, 4) {'x': 5, 'y': 6}
D) Error
9. What does this JSON operation do?
A) Alice
B) Error
C) '{"name": "Alice", "age": 25}'
D) None
10. What will happen if this function is called with sum_numbers(5)?
A) 5
B) 15
C) Error
D) 10
11. What will be the output of the following code?
A) 5
B) 8
C) 15
D) Error
12. What is the output of this Python code?
A) [0, 2, 4, 6, 8]
B) [1, 3, 5, 7, 9]
C) [2, 4, 6, 8, 10]
D) Error
13. What does the following code do?
A) {1, 2, 3, 4}
B) {1, 2, 3}
C) Error
D) None
14. What is the result of the following code?
A) 3
B) 6
C) 1
D) Error
15. What does the following code do?
A) Prints the current working directory.
B) Creates a new directory.
C) Deletes a file.
D) None
16. What is the output of this code?
A) 16
B) 4
C) 8
D) Error
17. What does the following code do?
A) [1, 2, 3, 4, 5]
B) [1, 2, 5, 3, 4]
C) [1, 5, 2, 3, 4]
D) Error
18. What will be the output of this Python code?
A) 15
B) 5
C) 10
D) Error
19. What does the following code do?
A) 6
B) 3
C) 1
D) Error
20. What will happen if this code is executed?
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [1, 2, 3, 4]
D) Error
21. What is the output of this code?
A) [1, 2, 3, 4, 5]
B) [1, 3, 5]
C) [2, 4]
D) Error
22. What is the output of this code?
A) hello
B) Hello
C) HELLO
D) Error
23. What does this code do?
A) ['Hello', 'World']
B) Hello World
C) ['Hello']
D) Error
24. What will the output of the following code be?
A) hel
B) ell
C) hello
D) Error
25. What does the following code do?
A) [1, 2, 3, 4]
B) [1, 2, 3]
C) [1, 2]
D) Error
1. What is the output of the following code?
Explanation: The default list persists across function calls.
a) [1] [2] [3]
b) [1] [1, 2] [1, 2, 3]
c) [1] [1] [1]
d) None None None
2. What does the following code print?
Explanation: ::2 takes every second character: "P", "t", "o".
a) Pto
b) Pytho
c) Phtn
d) Error
3. What is the output of the following?
Explanation: b is a reference to a, so modifying b also modifies a.
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) None
d) Error
4. What does this code print?
Explanation: The default list persists between calls unless explicitly overridden.
a) [10] [20] [30]
b) [10] [20] [10, 30]
c) [10] [20] [10, 30]
d) [10] [20] [10, 20, 30]
5. What is the output of this?
Explanation: a[:] creates a copy of a, so modifying b does not affect a.
a) [1, 2, 3, 4]
b) [1, 2, 3, 4, 5]
c) [1, 2, 3, 4, 5, 6]
d) Error
6. What does this code output?
Explanation: y += [4, 5] modifies x since y is just a reference to x.
a) [1, 2, 3]
b) [1, 2, 3, 4, 5]
c) Error
d) [4, 5]
7. What is the result of this code?
Explanation: An empty string is False, while a string with a space is True.
a) True True
b) True False
c) False False
d) False True
8. What does this code output?
Explanation: 3 2 is evaluated first (9), then 2 9 (512).
a) 64
b) 512
c) Error
d) 256
9. What is the result of this code?
a) abc
b) def
c) cde
d) Error
10. What does this code print?
Explanation: The default mutable list persists between function calls.
a) [1] [2] [3]
b) [1] [1, 2] [3]
c) [1] [1, 2] [1, 2, 3]
d) [1] [2] [1, 2, 3]
25. What will the output of this code snippet be?
B) 20
D) Error
C) 30
A) 10
26. What does this function return?
D) Error
C) A single integer
B) A list of cubes
A) A list of squares
27. What will happen if this code is executed?
C) It will raise an exception
D) None of the above
B) It will print 'World'
A) It will print 'Hello'
In programming, conditions help control the flow of a program by making decisions. When a condition is True, a certain block of code is executed. If the condition is False, what happens next?
An expression of a conditional
another block of code (typically under an t) may be executed instead else or elif statement
What does this expression say ?
i is less than and or equal to 5
Condition is greater i greater than 5 and has to be True for the next block f the conditional is true
Question 1: What will be the output of the following code?
A) Greater than 5
B) Less than or equal to 5
C) Error
D) No output
Question 2: What will be the final value of count after executing the following code?
A) 4
B) 5
C) 6
D) Infinite loop
Question 3: How many times will the loop run?
A) 2
B) 3
C) 4
D) Infinite
Question 4: What will be the output of the following code?
A) 0 1 2 3 4 5
B) 0 1 2 3 4 5 6
C) 1 2 3 4 5
D) 0 1 2 3 4
Question 5: What will be the output of the following if-else statement?
A) Even
B) Odd
C) Error
D) No output
Question 6: What will be printed when this code runs?
A) Condition met
B) Condition not met
C) Error
D) No output
Question 7: Which of the following is the correct syntax for an if-elif-else statement?
Question 1: What will be the output of the following code?
A) Greater than 5
B) Less than or equal to 5
C) Error
D) No output
Question 2: Which of the following is the correct syntax for an if statement?
A) if x > 10 then:
B) if (x > 10):
C) if x > 10:
D) if x > 10 {}
Question 3: What will be printed when this code runs?
A) Condition met
B) Condition not met
C) Error
D) No output
Question 4: What will be the output of the following if-else statement?
A) Even
B) Odd
C) Error
D) No output
Question 5: What will be the output of the following code?
A) 0 1 2 3
B) 1 2 3 4
C) 0 1 2 3 4
D) Infinite loop
Question 6: How many times will the loop execute?
A) 2
B) 3
C) 4
D) Infinite
Question 7: Which of the following is the correct syntax for an if-elif-else statement?
1. What is the primary purpose of a while loop in Python?
A) To execute a block of code a specific number of times
B) To execute a block of code as long as a condition is True
C) To execute a block of code only once
D) To define a function
2. What will be the output of the following code?
A) 0 1 2 3
B) 0 1 2
C) 1 2 3
D) Infinite loop
3. How can you exit a while loop prematurely in Python?
A) Using the continue statement
B) Using the break statement
C) Using the return statement
D) By setting the condition to False manually
4. What will be the output of the following code?
A) 1 2 3 4 5
B) 1 2 4 5
C) 1 2 3
D) Infinite loop
5. What will happen if the condition in a while loop never becomes False?
A) The program will terminate immediately
B) The loop will run indefinitely (infinite loop)
C) The program will display an error
D) The loop will execute only once
6. What is the output of the following code?
A) Hello
B) Hello Hello
C) Hello Hello Hello
D) Infinite loop
7. Which statement is used to skip the rest of the current iteration in a while loop and move to the next iteration?
A) break
B) continue
C) pass
D) return
8. What is wrong with the following code?
A) Nothing is wrong; it runs correctly
B) The loop will run indefinitely (infinite loop)
C) i is not initialized properly
D) while loops cannot use comparison operators
9. How many times will the following loop execute?
A) 2 times
B) 3 times
C) 5 times
D) Infinite times
10. What will be the last number printed in the following code?
A) 9
B) 10
C) 11
D) Infinite loop
Question 1: What will be the output of the following code?
A) Greater than 5
B) Less than or equal to 5
C) Error
D) No output
Question 2: Which of the following is the correct syntax for an if statement?
A) if x > 10 then:
B) if (x > 10):
C) if x > 10:
D) if x > 10 {}
Question 3: What will be printed when this code runs?
A) Condition met
B) Condition not met
C) Error
D) No output
Question 4: What will be the output of the following if-else statement?
A) Even
B) Odd
C) Error
D) No output
Question 5: What will be the output of the following code?
A) 0 1 2 3
B) 1 2 3 4
C) 0 1 2 3 4
D) Infinite loop
Question 6: How many times will the loop execute?
A) 2
B) 3
C) 4
D) Infinite
Question 7: Which of the following is the correct syntax for an if-elif-else statement?
Question 8: What is the output of the following code using an augmented assignment operator?
A) 5
B) 8
C) 3
D) Error
10. What will be the last number printed in the following code?
python
CopyEdit
A) 9
B) 10
C) 11
D) Infinite loop
1. What is the output of the following code?
Explanation:
The expression x > y checks if x (which is 10) is greater than y (which is 5). Since 10 is indeed greater than 5, the result is True.
A) True
B) False
C) None
D) Error
1. What is the output of the following code?
The expression x > y checks if x (which is 10) is greater than y (which is 5). Since 10 is indeed greater than 5, the result is True.
A) True
B) False
C) None
D) Error
2. What will be the output of the following code?
Explanation:
The if statement checks if a == b. Since both a and b are 20, the condition evaluates to True, and "Equal" is printed.
A) Equal
B) Not equal
C) True
D) False
3. What is the output of the following code?
Explanation:
In Python, any value that evaluates to False in a conditional statement includes values like 0, None, False, and empty collections (e.g., [], {}). Since x is 0, which is considered False, the else block is executed, and "False" is printed.
A) True
B) False
C) Nothing will be printed
D) Error
4. Which of the following statements is true about the elif keyword in Python?
The elif keyword allows you to check additional conditions if the previous if or elif conditions were False. It can be used multiple times to check multiple conditions sequentially.
A) It is used to start a loop.
B) It is used to check multiple conditions in an if block.
C) It is used to define a function.
D) It terminates the if block.
Question 6: How many times will the loop execute?
A) 2
B) 3
C) 4
D) Infinite
Question 2: Which of the following is the correct syntax for an if statement?
A) if x > 10 then:
B) if (x > 10):
C) if x > 10:
D) if x > 10 {}
Question 3: What will be printed when this code runs?
A) Condition met
B) Condition not met
C) Error
D) No output
Question 4: What will be the output of the following if-else statement?
A) Even
B) Odd
C) Error
D) No output
Question 5: What will be the output of the following code?
A) 0 1 2 3
B) 1 2 3 4
C) 0 1 2 3 4
D) Infinite loop
Question 6: How many times will the loop execute?
A) 2
B) 3
C) 4
D) Infinite
Question: What will be the result of the following code in Python?
a) ["apple", "banana", "cherry"]
b) ["apple", "banana", "apple"]
c) ["apple", "banana", "apple", "cherry"]
d) Error: Lists cannot have duplicate values.
Question: After executing this code, what will be the state of my_list?
a) ["banana", "cherry"]
b) ["apple", "banana", "cherry"]
c) ["apple", "cherry", "banana"]
d) ["apple", "cherry"]
Question: After executing this code, what will be the state of my_list?
a) ["banana", "cherry"]
b) ["apple", "banana", "cherry"]
c) ["apple", "cherry", "banana"]
d) ["apple", "cherry"]
Question: Given the following tuple:
What will be the output of the following code?
Explanation: The list inside the tuple is mutable, so we can modify its elements. However, the tuple itself is immutable, so we cannot change the tuple structure (e.g., we can't add or remove elements from it).
(10, 'orange', [5, 7], (2, 3))
(10, 'orange', [5, 7, 99], (2, 3))
(10, 'orange', [99 7, 99], (2, 3))
(10, 'orange', [5, 99, 99], (2, 3))
What will be the output of the following code?
a) (10, "orange", [5, 7, 9], (2, 3))
b) (10, "orange", [5, 7, 99], (2, 3))
c) (10, "orange", [5, 99, 9], (2, 3))
d) Error: Tuples are immutable.
What will be the resulting tuple after running the following code?
a) (1, 2, 3, [10, 99, 30])
b) (1, 2, 3, [10, 20, 30])
c) (1, 2, 3, [10, 20, 99])
d) Error: List index out of range.
What will be the resulting tuple after running the following code?
a) (1, 2, 3, [10, 99, 30])
b) (1, 2, 3, [10, 20, 30])
c) (1, 2, 3, [10, 20, 99])
d) Error: List index out of range.
What will be the output of the following code?
a) (1, 2, 3, [100, 5, 6], "apple")
b) (1, 2, 3, [4, 5, 6], "apple")
c) (1, 2, 3, [4, 5, 6], "banana")
d) Error: Tuples are immutable.
Given the following code, what will the output be?
a) ("cat", "dog", ["turtle", "bird"], "rabbit")
b) ("cat", "dog", ["fish", "bird"], "rabbit")
c) ("cat", "dog", ["fish", "turtle"], "rabbit")
d) Error: Lists inside tuples cannot be modified.
What will be the output of the following code?
a) (1, 2, 3, (10, 20), [30, 40, 99])
b) (1, 2, 3, (10, 20), [30, 40, 50])
c) (1, 2, 3, (10, 20), [99, 40, 50])
d) Error: You cannot modify lists inside tuples.
What will the result be if you execute the following code?
a) ([1, 99, 3], (4, 5), "apple")
b) ([1, 2, 3], (4, 5), "apple")
c) ([1, 2, 3], (99, 5), "apple")
d) Error: You cannot modify lists inside tuples.
What will be the output of the following code?
a) ('red', 'blue', [10, 20, 99], 'green')
b) ('red', 'blue', [10, 99, 30], 'green')
c) ('red', 'blue', [99, 20, 30], 'green')
d) Error: Tuples are immutable.
What will be the output if you execute this code?
a) ('grape', 'banana', [1, 2, 3], 'cherry')
b) ('apple', 'banana', [1, 2, 3], 'cherry')
c) Error: 'tuple' object does not support item assignment
d) None
Question 12: What does the not operator do in Python?
A) Negates a boolean value
B) Performs bitwise negation
C) Returns None
D) Creates a loop
Question 11: What will be the result of the following expression?
True or False and False
A) True
B) False
C) None
D) Error
Question 9: What will be the output of the following code using logical operators?
A) True
B) False
C) None
D) Error
Question 8: What is the output of the following code using an augmented assignment operator?
A) 5
B) 8
C) 3
D) Error
Question 9: What will be the output of the following code using logical operators?
A) True
B) False
C) None
D) Error
