CARVIEW |
Special functions Python
Question 1
numbers = [1, 2, 3, 4, 5]
squares = list(map(lambda x: x**2, numbers))
What does the squares list contain after executing the code?
[1, 2, 3, 4, 5]
[1, 4, 9, 16, 25]
[2, 4, 6, 8, 10]
[0, 1, 4, 9, 16]
Question 2
words = ["apple", "banana", "cherry"]
filtered_words = list(filter(lambda x: len(x) > 5, words))
What is the value of filtered_words after executing the code?
["apple"]
["banana"]
["cherry"]
["banana", "cherry"]
Question 3
nums1 = [1, 2, 3]
nums2 = [4, 5, 6]
result = list(zip(nums1, nums2))
What is the value of result after executing the code?
[(1, 4), (2, 5), (3, 6)]
[5, 7, 9]
[(1, 2, 3), (4, 5, 6)]
[1, 2, 3, 4, 5, 6]
Question 4
numbers = [1, 2, 3, 4, 5]
squared_odd = list(map(lambda x: x**2, filter(lambda x: x % 2 != 0, numbers)))
What does the squared_odd list contain after executing the code?
[1, 9, 25]
[1, 4, 9, 16, 25]
[2, 4]
[9, 25]
Question 5
numbers = [1, 2, 3, 4, 5]
product = lambda x, y: x * y
result = reduce(product, numbers)
What is the value of result after executing the code?
120
15
30
0
Question 6
What does the ord function in Python do?
Rounds a floating-point number to the nearest integer
Returns the Unicode code point of a character
Converts a number to its hexadecimal representation
Finds the absolute value of a number
Question 7
char = 'A'
ascii_value = ord(char)
What is the value of ascii_value after executing the code?
65
66
67
68
Question 8
Q8-code_point = 97
character = chr(code_point)
What is the value of character after executing the code?
A) 'A'
B) 'B'
C) 'a'
D) 'b'
Question 9
Q9-text = "Python"
ascii_values = [ord(char) for char in text]
What is the value of ascii_values after executing the code?
A) [80, 121, 116, 104, 111, 110]
B) [112, 121, 116, 104, 111, 110]
C) [72, 101, 108, 108, 111, 32]
D) [65, 66, 67, 68, 69, 70]
Question 10
Q10-What is the result of the expression chr(ord('A') + 3)?
A) 'D'
B) 'E'
C) 'B'
D) 'C'
There are 15 questions to complete.