wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

General Knowledge Quiz

Total questions: 114

Worksheet time: 57mins

Name
Class
Date
1.

What will What is the output of the following code?

a)

A. [1] and [2]

b)

B. [1] and [1, 2]

c)

C. [1, 2] and [1, 2]

d)

D. [1] and [2]

2.

3. What is the result of this lambda function?

a)

10

b)

12

c)

Error

d)

12

3.

What will be the output of this python program?

a)

10

b)

15

c)

Error

d)

5

4.

What is

a)

101

b)

220

c)

Error

d)

12

5.

4. What will be the output of this Python program?

a)

10

b)

5

c)

15

d)

Error

6.

What will

a)

1

b)

2

c)

3

d)

4

7.

What is

a)

101

b)

220

c)

Error

d)

12

8.

What will

a)

10

b)

5

c)

15

d)

Error

9.

What will

a)

1

b)

2

c)

3

d)

4

10.

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

a)

A) [1] [2] [3] [4]

b)

B) [1] [1, 2] [3] [1, 2, 4]

c)

C) [1] [2] [3] [4]

d)

D) [1] [1, 2] [3] [1, 2, 4]

11.

10. What will happen if this function is called with sum_numbers(5)?

a)

A) 5

b)

B) 15

c)

C) Error

d)

D) 10

12.

9. What does this JSON operation do?

a)

A) Alice

b)

B) Error

c)

C) '{"name": "Alice", "age": 25}'

d)

D) None

13.

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

a)
  • A) [1] [2] [3] [4]

b)
  • B) [1] [1, 2] [3] [1, 2, 4]

c)
  • C) [1] [2] [3] [4]

d)
  • D) [1] [1, 2] [3] [1, 2, 4]

14.

2. What does the following Python snippet output?

a)
  • A) False False False

b)
  • B) True True True

c)
  • C) False True False

d)
  • D) True False True

15.

3. What is the result of this lambda function?

a)
  • A) 10

b)
  • B) 12

c)
  • C) 20

d)
  • D) Error

16.

4. What will be the output of this Python program?

a)
  • A) 10

b)
  • B) 5

c)
  • C) 15

d)
  • D) Error

17.

5. What does the following code do?

a)
  • A) [1, 4, 9, 16, 25]

b)
  • B) [0, 1, 4, 9, 16]

c)
  • C) [0, 1, 2, 3, 4]

d)
  • D) Error

18.

6. What is the output of this code?

a)
  • A) [1, 2, 3]

b)
  • B) [1, 2, 3, 4]

c)
  • C) Error

d)
  • D) None

19.

7. What does this regex pattern match?

a)
  • A) 123-456-7890

b)
  • B) 123-456

c)
  • C) Error

d)
  • D) None

20.

8. What will the following code output?

a)
  • A) 1 2 (3, 4) {'x': 5, 'y': 6}

b)
  • B) 1 2 3 4 x=5 y=6

c)
  • C) (1, 2) (3, 4) {'x': 5, 'y': 6}

d)
  • D) Error

21.

9. What does this JSON operation do?

a)
  • A) Alice

b)
  • B) Error

c)
  • C) '{"name": "Alice", "age": 25}'

d)
  • D) None

22.

10. What will happen if this function is called with sum_numbers(5)?

a)
  • A) 5

b)
  • B) 15

c)
  • C) Error

d)
  • D) 10

23.

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

a)
  • A) 5

b)
  • B) 8

c)
  • C) 15

d)
  • D) Error

24.

12. What is the output of this Python code?

a)
  • A) [0, 2, 4, 6, 8]

b)
  • B) [1, 3, 5, 7, 9]

c)
  • C) [2, 4, 6, 8, 10]

d)
  • D) Error

25.

13. What does the following code do?

a)
  • A) {1, 2, 3, 4}

b)
  • B) {1, 2, 3}

c)
  • C) Error

d)
  • D) None

26.

14. What is the result of the following code?

a)
  • A) 3

b)
  • B) 6

c)
  • C) 1

d)
  • D) Error

27.

15. What does the following code do?

a)
  • A) Prints the current working directory.

b)
  • B) Creates a new directory.

c)
  • C) Deletes a file.

d)
  • D) None

28.

16. What is the output of this code?

a)
  • A) 16

b)
  • B) 4

c)
  • C) 8

d)
  • D) Error

29.

17. What does the following code do?

a)
  • A) [1, 2, 3, 4, 5]

b)
  • B) [1, 2, 5, 3, 4]

c)
  • C) [1, 5, 2, 3, 4]

d)
  • D) Error

30.

18. What will be the output of this Python code?

a)
  • A) 15

b)
  • B) 5

c)
  • C) 10

d)
  • D) Error

31.

19. What does the following code do?

a)
  • A) 6

b)
  • B) 3

c)
  • C) 1

d)
  • D) Error

32.

20. What will happen if this code is executed?

a)
  • A) [1, 2, 3]

b)
  • B) [1, 2, 3, 4]

c)
  • C) [1, 2, 3, 4]

d)
  • D) Error

33.

21. What is the output of this code?

a)
  • A) [1, 2, 3, 4, 5]

b)
  • B) [1, 3, 5]

c)
  • C) [2, 4]

d)
  • D) Error

34.

22. What is the output of this code?

a)
  • A) hello

b)
  • B) Hello

c)
  • C) HELLO

d)
  • D) Error

35.

23. What does this code do?

a)
  • A) ['Hello', 'World']

b)
  • B) Hello World

c)
  • C) ['Hello']

d)
  • D) Error

36.

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

a)
  • A) hel

b)
  • B) ell

c)
  • C) hello

d)
  • D) Error

37.

25. What does the following code do?

a)
  • A) [1, 2, 3, 4]

b)
  • B) [1, 2, 3]

c)
  • C) [1, 2]

d)
  • D) Error

38.

1. What is the output of the following code?

Explanation: The default list persists across function calls.

a)

a) [1] [2] [3]

b)

b) [1] [1, 2] [1, 2, 3]

c)

c) [1] [1] [1]

d)

d) None None None

39.

2. What does the following code print?

Explanation: ::2 takes every second character: "P", "t", "o".

a)

a) Pto

b)

b) Pytho

c)

c) Phtn

d)

d) Error

40.

3. What is the output of the following?

Explanation: b is a reference to a, so modifying b also modifies a.

a)

a) [1, 2, 3]

b)

b) [1, 2, 3, 4]

c)

c) None

d)

d) Error

41.

4. What does this code print?

Explanation: The default list persists between calls unless explicitly overridden.

a)

a) [10] [20] [30]

b)

b) [10] [20] [10, 30]

c)

c) [10] [20] [10, 30]

d)

d) [10] [20] [10, 20, 30]

42.

5. What is the output of this?

Explanation: a[:] creates a copy of a, so modifying b does not affect a.

a)

a) [1, 2, 3, 4]

b)

b) [1, 2, 3, 4, 5]

c)

c) [1, 2, 3, 4, 5, 6]

d)

d) Error

43.

6. What does this code output?

Explanation: y += [4, 5] modifies x since y is just a reference to x.

a)

a) [1, 2, 3]

b)

b) [1, 2, 3, 4, 5]

c)

c) Error

d)

d) [4, 5]

44.

7. What is the result of this code?

Explanation: An empty string is False, while a string with a space is True.

a)

a) True True

b)

b) True False

c)

c) False False

d)

d) False True

45.

8. What does this code output?

Explanation: 3 2 is evaluated first (9), then 2 9 (512).

a)

a) 64

b)

b) 512

c)

c) Error

d)

d) 256

46.

9. What is the result of this code?

a)

a) abc

b)

b) def

c)

c) cde

d)

d) Error

47.

10. What does this code print?

Explanation: The default mutable list persists between function calls.

a)

a) [1] [2] [3]

b)

b) [1] [1, 2] [3]

c)

c) [1] [1, 2] [1, 2, 3]

d)

d) [1] [2] [1, 2, 3]

48.

25. What will the output of this code snippet be?

a)

  • B) 20

b)

  • D) Error

c)

  • C) 30

d)

  • A) 10

49.

26. What does this function return?

a)

  • D) Error

b)

  • C) A single integer

c)

  • B) A list of cubes

d)

  • A) A list of squares

50.

27. What will happen if this code is executed?

a)

  • C) It will raise an exception

b)

  • D) None of the above

c)

  • B) It will print 'World'

d)

  • A) It will print 'Hello'

51.

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?

a)

An expression of a conditional

b)

another block of code (typically under an t) may be executed instead else or elif statement

52.

What does this expression say ?

a)

i is less than and or equal to 5

b)

Condition is greater i greater than 5 and has to be True for the next block f the conditional is true

53.

Question 1: What will be the output of the following code?

a)

A) Greater than 5

b)

B) Less than or equal to 5

c)

C) Error

d)

D) No output

54.

Question 2: What will be the final value of count after executing the following code?

a)

A) 4

b)

B) 5

c)

C) 6

d)

D) Infinite loop

55.

Question 3: How many times will the loop run?

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) Infinite

56.

Question 4: What will be the output of the following code?

a)

A) 0 1 2 3 4 5

b)

B) 0 1 2 3 4 5 6

c)

C) 1 2 3 4 5

d)

D) 0 1 2 3 4

57.

Question 5: What will be the output of the following if-else statement?

a)

A) Even

b)

B) Odd

c)

C) Error

d)

D) No output

58.

Question 6: What will be printed when this code runs?

a)

A) Condition met

b)

B) Condition not met

c)

C) Error

d)

D) No output

59.

Question 7: Which of the following is the correct syntax for an if-elif-else statement?

a)

b)

c)

d)

60.

Question 1: What will be the output of the following code?

a)

A) Greater than 5

b)

B) Less than or equal to 5

c)

C) Error

d)

D) No output

61.

Question 2: Which of the following is the correct syntax for an if statement?

a)

A) if x > 10 then:

b)

B) if (x > 10):

c)

C) if x > 10:

d)

D) if x > 10 {}

62.

Question 3: What will be printed when this code runs?

a)

A) Condition met

b)

B) Condition not met

c)

C) Error

d)

D) No output

63.

Question 4: What will be the output of the following if-else statement?

a)

A) Even

b)

B) Odd

c)

C) Error

d)

D) No output

64.

Question 5: What will be the output of the following code?

a)

A) 0 1 2 3

b)

B) 1 2 3 4

c)

C) 0 1 2 3 4

d)

D) Infinite loop

65.

Question 6: How many times will the loop execute?

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) Infinite

66.

Question 7: Which of the following is the correct syntax for an if-elif-else statement?

a)

b)

c)

d)

67.

1. What is the primary purpose of a while loop in Python?

a)

A) To execute a block of code a specific number of times

b)

B) To execute a block of code as long as a condition is True

c)

C) To execute a block of code only once

d)

D) To define a function

68.

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

a)

A) 0 1 2 3

b)

B) 0 1 2

c)

C) 1 2 3

d)

D) Infinite loop

69.

3. How can you exit a while loop prematurely in Python?

a)

A) Using the continue statement

b)

B) Using the break statement

c)

C) Using the return statement

d)

D) By setting the condition to False manually

70.

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

a)

A) 1 2 3 4 5

b)

B) 1 2 4 5

c)

C) 1 2 3

d)

D) Infinite loop

71.

5. What will happen if the condition in a while loop never becomes False?

a)

A) The program will terminate immediately

b)

B) The loop will run indefinitely (infinite loop)

c)

C) The program will display an error

d)

D) The loop will execute only once

72.

6. What is the output of the following code?

a)

A) Hello

b)

B) Hello Hello

c)

C) Hello Hello Hello

d)

D) Infinite loop

73.

7. Which statement is used to skip the rest of the current iteration in a while loop and move to the next iteration?

a)

A) break

b)

B) continue

c)

C) pass

d)

D) return

74.

8. What is wrong with the following code?

a)

A) Nothing is wrong; it runs correctly

b)

B) The loop will run indefinitely (infinite loop)

c)

C) i is not initialized properly

d)

D) while loops cannot use comparison operators

75.

9. How many times will the following loop execute?

a)

A) 2 times

b)

B) 3 times

c)

C) 5 times

d)

D) Infinite times

76.

10. What will be the last number printed in the following code?

a)

A) 9

b)

B) 10

c)

C) 11

d)

D) Infinite loop

77.

Question 1: What will be the output of the following code?

a)

A) Greater than 5

b)

B) Less than or equal to 5

c)

C) Error

d)

D) No output

78.

Question 2: Which of the following is the correct syntax for an if statement?

a)

A) if x > 10 then:

b)

B) if (x > 10):

c)

C) if x > 10:

d)

D) if x > 10 {}

79.

Question 3: What will be printed when this code runs?

a)

A) Condition met

b)

B) Condition not met

c)

C) Error

d)

D) No output

80.

Question 4: What will be the output of the following if-else statement?

a)

A) Even

b)

B) Odd

c)

C) Error

d)

D) No output

81.

Question 5: What will be the output of the following code?

a)

A) 0 1 2 3

b)

B) 1 2 3 4

c)

C) 0 1 2 3 4

d)

D) Infinite loop

82.

Question 6: How many times will the loop execute?

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) Infinite

83.

Question 7: Which of the following is the correct syntax for an if-elif-else statement?

a)

b)

c)

d)

84.

Question 8: What is the output of the following code using an augmented assignment operator?

a)

A) 5

b)

B) 8

c)

C) 3

d)

D) Error

85.

10. What will be the last number printed in the following code?

python

CopyEdit

a)

A) 9

b)

B) 10

c)

C) 11

d)

D) Infinite loop

86.

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)

A) True

b)

B) False

c)

C) None

d)

D) Error

87.

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)

A) True

b)

B) False

c)

C) None

d)

D) Error

88.

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)

A) Equal

b)

B) Not equal

c)

C) True

d)

D) False

89.

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)

A) True

b)

B) False

c)

C) Nothing will be printed

d)

D) Error

90.

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)

A) It is used to start a loop.

b)

B) It is used to check multiple conditions in an if block.

c)

C) It is used to define a function.

d)

D) It terminates the if block.

91.

Question 6: How many times will the loop execute?

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) Infinite

92.

Question 2: Which of the following is the correct syntax for an if statement?

a)

A) if x > 10 then:

b)

B) if (x > 10):

c)

C) if x > 10:

d)

D) if x > 10 {}

93.

Question 3: What will be printed when this code runs?

a)

A) Condition met

b)

B) Condition not met

c)

C) Error

d)

D) No output

94.

Question 4: What will be the output of the following if-else statement?

a)

A) Even

b)

B) Odd

c)

C) Error

d)

D) No output

95.

Question 5: What will be the output of the following code?

a)

A) 0 1 2 3

b)

B) 1 2 3 4

c)

C) 0 1 2 3 4

d)

D) Infinite loop

96.

Question 6: How many times will the loop execute?

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) Infinite

97.

Question: What will be the result of the following code in Python?

a)

a) ["apple", "banana", "cherry"]

b)

b) ["apple", "banana", "apple"]

c)

c) ["apple", "banana", "apple", "cherry"]

d)

d) Error: Lists cannot have duplicate values.

98.

Question: After executing this code, what will be the state of my_list?

a)
  • a) ["banana", "cherry"]

b)
  • b) ["apple", "banana", "cherry"]

c)
  • c) ["apple", "cherry", "banana"]

d)
  • d) ["apple", "cherry"]

99.

Question: After executing this code, what will be the state of my_list?

a)
  • a) ["banana", "cherry"]

b)
  • b) ["apple", "banana", "cherry"]

c)
  • c) ["apple", "cherry", "banana"]

d)
  • d) ["apple", "cherry"]

100.

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).

a)

(10, 'orange', [5, 7], (2, 3))

b)

(10, 'orange', [5, 7, 99], (2, 3))

c)

(10, 'orange', [99 7, 99], (2, 3))

d)

(10, 'orange', [5, 99, 99], (2, 3))

101.

What will be the output of the following code?

a)

a) (10, "orange", [5, 7, 9], (2, 3))

b)

b) (10, "orange", [5, 7, 99], (2, 3))

c)

c) (10, "orange", [5, 99, 9], (2, 3))

d)

d) Error: Tuples are immutable.

102.

What will be the resulting tuple after running the following code?

a)

a) (1, 2, 3, [10, 99, 30])

b)

b) (1, 2, 3, [10, 20, 30])

c)

c) (1, 2, 3, [10, 20, 99])

d)

d) Error: List index out of range.

103.

What will be the resulting tuple after running the following code?

a)

a) (1, 2, 3, [10, 99, 30])

b)

b) (1, 2, 3, [10, 20, 30])

c)

c) (1, 2, 3, [10, 20, 99])

d)

d) Error: List index out of range.

104.

What will be the output of the following code?

a)

a) (1, 2, 3, [100, 5, 6], "apple")

b)

b) (1, 2, 3, [4, 5, 6], "apple")

c)

c) (1, 2, 3, [4, 5, 6], "banana")

d)

d) Error: Tuples are immutable.

105.

Given the following code, what will the output be?

a)

a) ("cat", "dog", ["turtle", "bird"], "rabbit")

b)

b) ("cat", "dog", ["fish", "bird"], "rabbit")

c)

c) ("cat", "dog", ["fish", "turtle"], "rabbit")

d)

d) Error: Lists inside tuples cannot be modified.

106.

What will be the output of the following code?

a)

a) (1, 2, 3, (10, 20), [30, 40, 99])

b)

b) (1, 2, 3, (10, 20), [30, 40, 50])

c)

c) (1, 2, 3, (10, 20), [99, 40, 50])

d)

d) Error: You cannot modify lists inside tuples.

107.

What will the result be if you execute the following code?

a)

a) ([1, 99, 3], (4, 5), "apple")

b)

b) ([1, 2, 3], (4, 5), "apple")

c)

c) ([1, 2, 3], (99, 5), "apple")

d)

d) Error: You cannot modify lists inside tuples.

108.

What will be the output of the following code?

a)

a) ('red', 'blue', [10, 20, 99], 'green')

b)

b) ('red', 'blue', [10, 99, 30], 'green')

c)

c) ('red', 'blue', [99, 20, 30], 'green')

d)

d) Error: Tuples are immutable.

109.

What will be the output if you execute this code?

a)

a) ('grape', 'banana', [1, 2, 3], 'cherry')

b)

b) ('apple', 'banana', [1, 2, 3], 'cherry')

c)

c) Error: 'tuple' object does not support item assignment

d)

d) None

110.

Question 12: What does the not operator do in Python?

a)

A) Negates a boolean value

b)

B) Performs bitwise negation

c)

C) Returns None

d)

D) Creates a loop

111.

Question 11: What will be the result of the following expression?

True or False and False

a)

A) True

b)

B) False

c)

C) None

d)

D) Error

112.

Question 9: What will be the output of the following code using logical operators?

a)

A) True

b)

B) False

c)

C) None

d)

D) Error

113.

Question 8: What is the output of the following code using an augmented assignment operator?

a)

A) 5

b)

B) 8

c)

C) 3

d)

D) Error

114.

Question 9: What will be the output of the following code using logical operators?

a)

A) True

b)

B) False

c)

C) None

d)

D) Error