What will be the output of the code?
❌ 12
❌ 52
✅ 13
❌ 60
❌ Error
❌ None of the above
Explanation:
In the above code, obj.quantity has been initialised to 10. There are a total of three items in the dictionary, price, quantity and bags. Hence, len(obj.__dict__) is 3.
❌ 12
❌ 52
✅ 13
❌ 60
❌ Error
❌ None of the above
Explanation:
In the above code, obj.quantity has been initialised to 10. There are a total of three items in the dictionary, price, quantity and bags. Hence, len(obj.__dict__) is 3.
What will be the output of the code?
❌ Exception is thrown
❌ Count.test=25, k=25
✅ Count.test=25, k=0
❌ Count.test=0, k=0
❌ None of the above
Explanation:
The program has no error. Here, test is a member of the class while k isn’t. Hence test keeps getting incremented 25 time while k remains 0.
❌ Exception is thrown
❌ Count.test=25, k=25
✅ Count.test=25, k=0
❌ Count.test=0, k=0
❌ None of the above
Explanation:
The program has no error. Here, test is a member of the class while k isn’t. Hence test keeps getting incremented 25 time while k remains 0.
What will be the result of the code?
❌ [[1, 2], [3, 4], [5, 6]]
❌ [[1, 2], [3, 4]]
✅ [(1, 3, 5), (2, 4, 6)]
❌ [1, 2, 3, 4, 5, 6]
❌ Error
❌ None of the above
Explanation:
The code uses a zip function to transpose the given matrix.
Zip is a built-in function that extracts data from the different columns and changes it into tuples. The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc. If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.
❌ [[1, 2], [3, 4], [5, 6]]
❌ [[1, 2], [3, 4]]
✅ [(1, 3, 5), (2, 4, 6)]
❌ [1, 2, 3, 4, 5, 6]
❌ Error
❌ None of the above
Explanation:
The code uses a zip function to transpose the given matrix.
Zip is a built-in function that extracts data from the different columns and changes it into tuples. The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc. If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.
What is the result of the code snippet?
❌ 2
✅ 3
❌ '2'
❌ '1'
❌ KeyError
❌ None of the above
Explanation:
Simple key-value pair is used recursively, D[1] = 1, str(1) = ‘1’.
So, D[str(D[1])] = D[‘1’] = 2, D[2] = ‘2’ and D[‘2’] = 3.
❌ 2
✅ 3
❌ '2'
❌ '1'
❌ KeyError
❌ None of the above
Explanation:
Simple key-value pair is used recursively, D[1] = 1, str(1) = ‘1’.
So, D[str(D[1])] = D[‘1’] = 2, D[2] = ‘2’ and D[‘2’] = 3.
What is the output of the code snippet?
✅ pYtHoN PrOgRaMmInG
❌ Python Programming
❌ python programming
❌ PYTHON PROGRAMMING
❌ Error
❌ None of the above
Explanation:
In this code snippet, we convert every element in odd index to lower case and every element in even index to uppercase.
✅ pYtHoN PrOgRaMmInG
❌ Python Programming
❌ python programming
❌ PYTHON PROGRAMMING
❌ Error
❌ None of the above
Explanation:
In this code snippet, we convert every element in odd index to lower case and every element in even index to uppercase.
What is the result of the code snippet?
❌ A
✅ B
❌ =
❌ AB
❌ A=B
❌ Error
❌ None of the above
Explanation:
In the above code, the assign value for a = 13 and b = 15.
There are three conditions mentioned in the code:
1. print("A") if a > b , here 13 is not greater than 15 so condition becomes false
2. print("=") if a == b , here 13 is not equal to 15 so condition becomes false
3. else print("B"), condition 1 and 2 will not be true so program control will switch to else part and output will be "B".
❌ A
✅ B
❌ =
❌ AB
❌ A=B
❌ Error
❌ None of the above
Explanation:
In the above code, the assign value for a = 13 and b = 15.
There are three conditions mentioned in the code:
1. print("A") if a > b , here 13 is not greater than 15 so condition becomes false
2. print("=") if a == b , here 13 is not equal to 15 so condition becomes false
3. else print("B"), condition 1 and 2 will not be true so program control will switch to else part and output will be "B".
What will be the output of the code?
❌ 5
❌ 6
✅ 9
❌ 12
❌ Error
❌ None of the above
Explanation:
The function my_func takes two arguments, x and y, with a default value of 2 for y. The function returns the value of x raised to the power of y.
In the code snippet, my_func is called with the argument 3, but no value is specified for y, so the default value of 2 is used. Therefore, my_func calculates and returns 3 ** 2, which equals 9.
As a result, the correct answer is 9.
❌ 5
❌ 6
✅ 9
❌ 12
❌ Error
❌ None of the above
Explanation:
The function my_func takes two arguments, x and y, with a default value of 2 for y. The function returns the value of x raised to the power of y.
In the code snippet, my_func is called with the argument 3, but no value is specified for y, so the default value of 2 is used. Therefore, my_func calculates and returns 3 ** 2, which equals 9.
As a result, the correct answer is 9.