Cyber Olympiad Class 10 - Sample question paper 11
Posted by Olympiad Tester on
Q1. What will be the output of the following Python code?
numbers = [2, 4, 6, 8, 10]
result = list(filter(lambda x: x % 3 == 0, numbers))
print(result)
a) [2, 4, 6, 8, 10]
b) [3, 6, 9]
c) [6]
d) [9]
Answer: c) [6]
Explanation: The code filters the numbers divisible by 3 using a lambda function.
Q2. In Python, what does the `__doc__` attribute provide for a function?
a) Documentation string of the function
b) Default arguments
c) Function name
d) Module name
Answer: a) Documentation string of the function
Explanation: The `__doc__` attribute contains the documentation string of a function.
Q3. What will be the output of the following Python code?
def outer_function(x):
def inner_function(y):
return x + y
return inner_function
result = outer_function(5)(3)
print(result)
a) 8
b) 15
c) 3
d) 53
Answer: a) 8
Explanation: The code defines a closure, and calling `outer_function(5)(3)` adds 5 and 3.
Q4. What is the purpose of the `random` module in Python?
a) Generating pseudo-random numbers
b) Sorting lists in random order
c) Shuffling elements in a list
d) Performing random mathematical operations
Answer: a) Generating pseudo-random numbers
Explanation: The `random` module is used for generating pseudo-random numbers in Python.
Q5. What will be the output of the following Python code?
def power(x, n=2):
return x ** n
result = power(4, 3)
print(result)
a) 64
b) 16
c) 8
d) 12
Answer: a) 64
Explanation: The function `power` calculates 4 to the power of 3.
Q6. In Python, how can you read a JSON file?
a) `open("file.json", "r")`
b) `json.read("file.json")`
c) `with open("file.json", "r") as file:`
d) `file = open("file.json", "read")`
Answer: c) `with open("file.json", "r") as file:`
Explanation: The `with` statement ensures proper file handling for reading a JSON file.
Q7. What is the purpose of the `map` function in Python?
a) Applies a function to each element in an iterable
b) Creates a map of values to keys
c) Generates a list of integers
d) Concatenates two lists
Answer: a) Applies a function to each element in an iterable
Explanation: The `map` function applies a specified function to each element in an iterable.
Q8. What is the purpose of the `global` keyword in Python?
a) Declaring a variable as global
b) Importing global modules
c) Indicating a global function
d) Accessing global variables inside a function
Answer: a) Declaring a variable as global
Explanation: The `global` keyword is used to declare a variable as global inside a function.
Q9. What will be the output of the following Python code?
string = "hello world"
result = string.split()
print(result)
a) 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'
b) ['hello', 'world']
c) 'hello world'
d) ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
Answer: b) ['hello', 'world']
Explanation: The `split` method splits the string into a list using whitespace as the default delimiter.
Q10. In Python, what is the purpose of the `finally` block in a `try` and `except` statement?
a) Executing code regardless of whether an exception occurs or not
b) Handling exceptions
c) Defining alternative code to execute when an exception occurs
d) Terminating the program
Answer: a) Executing code regardless of whether an exception occurs or not
Explanation: The `finally` block is used for executing code regardless of whether an exception occurs or not.
Q11. What will be the output of the following Python code?
numbers = [1, 2, 3, 4, 5]
result = list(map(lambda x: x * 2, numbers))
print(result)
a) [1, 4, 9, 16, 25]
b) [2, 4, 6, 8, 10]
c) [2, 4, 6, 8, 10]
d) [1, 2, 3, 4, 5]
Answer: b) [2, 4, 6, 8, 10]
Explanation: The `map` function doubles each element in the given list.
Q12. In Python, what is the purpose of the `*args` in a function definition?
a) Denotes keyword arguments
b) Represents a tuple of positional arguments
c) Specifies default arguments
d) Used for variable-length argument lists
Answer: d) Used for variable-length argument lists
Explanation: `*args` allows a function to accept a variable number of positional arguments.
Q13. What will be the output of the following Python code?
def greet(name="Guest"):
return f"Hello, {name}!"
result = greet("Alice")
print(result)
a) "Hello, Guest!"
b) "Hello, Alice!"
c) "Hello, World!"
d) "Hello, {name}!"
Answer: b) "Hello, Alice!"
Explanation: The function is called with the argument "Alice," so it overrides the default value.
Q14. What is the purpose of the `__name__` attribute in Python?
a) Returns the name of the module
b) Provides the name of the class
c) Retrieves the name of the function
d) Indicates whether the script is being run as the main program
Answer: a) Returns the name of the module
Explanation: The `__name__` attribute returns the name of the module in Python.
Q15. What will be the output of the following Python code?
import math
result = math.sqrt(16)
print(result)
a) 4
b) 8
c) 16
d) 2
Answer: a) 4
Explanation: The `sqrt` function from the `math` module calculates the square root of 16.
Q16. In Python, what does the `__repr__` method do?
a) Converts an object to a string representation
b) Defines the representation of an object for debugging
c) Compares objects for equality
d) Initializes an object
Answer: b) Defines the representation of an object for debugging
Explanation: The `__repr__` method defines the string representation of an object for debugging purposes.
Q17. What is the purpose of the `json.dumps` function in Python?
a) Loads JSON data from a file
b) Dumps Python data into a JSON string
c) Parses a JSON string into a Python object
d) Encodes JSON data
Answer: b) Dumps Python data into a JSON string
Explanation: The `json.dumps` function serializes Python data into a JSON-formatted string.
Q18. What will be the output of the following Python code?
def add_numbers(*args):
return sum(args)
result = add_numbers(1, 2, 3, 4, 5)
print(result)
a) 15
b) 10
c) 1
d) (1, 2, 3, 4, 5)
Answer: a) 15
Explanation: The `add_numbers` function sums up the provided arguments.
Q19. In Python, what does the `__len__` method do?
a) Defines the length of a list
b) Returns the number of elements in an iterable
c) Retrieves the length of a string
d) Initializes the length of a tuple
Answer: b) Returns the number of elements in an iterable
Explanation: The `__len__` method is used to get the number of elements in an iterable object.
Q20. What is the purpose of the `range` function in Python?
a) Creates a range object with a specified start and end
b) Generates a random range of numbers
c) Creates a sequence of numbers
d) Checks if a number is within a specified range
Answer: a) Creates a range object with a specified start and end
Explanation: The `range` function generates a sequence of numbers within a specified range.
Q21. What will be the output of the following Python code?
numbers = [1, 2, 3, 4, 5]
result = list(filter(lambda x: x % 2 == 0, numbers))
print(result)
a) [1, 3, 5]
b) [2, 4]
c) [1, 2, 3, 4, 5]
d) [2, 4, 6]
Answer: b) [2, 4]
Explanation: The `filter` function filters out the odd numbers from the given list.
Q22. In Python, what is the purpose of the `os.path.join` function?
a) Concatenates strings
b) Joins path components into a single path
c) Extracts the file extension from a path
d) Checks if a file exists
Answer: b) Joins path components into a single path
Explanation: `os.path.join` is used to join path components into a single path.
Q23. What will be the output of the following Python code?
def square_numbers(nums):
return [num ** 2 for num in nums]
numbers = [1, 2, 3, 4, 5]
result = square_numbers(numbers)
print(result)
a) [1, 4, 9, 16, 25]
b) [2, 4, 6, 8, 10]
c) [1, 2, 3, 4, 5]
d) [1, 8, 27, 64, 125]
Answer: a) [1, 4, 9, 16, 25]
Explanation: The function `square_numbers` squares each number in the given list.
Q24. In Python, what is the purpose of the `shutil` module?
a) Provides access to mathematical functions
b) Allows interaction with the operating system
c) Manages file operations
d) Performs string manipulation
Answer: c) Manages file operations
Explanation: The `shutil` module in Python is used for file operations and high-level file management tasks.
Q25. What will be the output of the following Python code?
def factorial(n):
return 1 if n == 0 else n * factorial(n - 1)
result = factorial(5)
print(result)
a) 10
b) 120
c) 25
d) 30
Answer: b) 120
Explanation: The function `factorial` calculates the factorial of 5 (5!).
Q26. In Python, what is the purpose of the `__init__` method in a class?
a) Initializes the class object
b) Creates a new instance of the class
c) Defines the representation of an object
d) Compares objects for equality
Answer: a) Initializes the class object
Explanation: The `__init__` method initializes the class object and sets its initial state.
Q27. What is the purpose of the `requests` module in Python?
a) Generates random numbers
b) Sends HTTP requests
c) Performs string formatting
d) Executes system commands
Answer: b) Sends HTTP requests
Explanation: The `requests` module is used for sending HTTP requests and handling responses in Python.
Q28. What will be the output of the following Python code?
string = "hello"
result = string.upper()
print(result)
a) "HELLO"
b) "hello"
c) "Hello"
d) "h, e, l, l, o"
Answer: a) "HELLO"
Explanation: The `upper` method converts all characters in the string to uppercase.
Q29. In Python, what is the purpose of the `time` module?
a) Manipulates date and time information
b) Measures the execution time of a program
c) Performs mathematical operations
d) Handles user input/output
Answer: a) Manipulates date and time information
Explanation: The `time` module in Python is used for working with date and time information.
Q30. What will be the output of the following Python code?
nums = [1, 2, 3, 4, 5]
result = sum(num ** 2 for num in nums)
print(result)
a) 15
b) 55
c) 30
d) 85
Answer: b) 55
Explanation: The code calculates the sum of the squares of numbers in the given list.