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.
What will be the output of the code?
✅ A. Buddy says Woof! Fluffy says Meow!
❌ B. Buddy says Meow! Fluffy says Woof!
❌ C. Buddy says Woof! Fluffy says Woof!
❌ D. Buddy says Meow! Fluffy says Meow!
❌ E. Error
❌ F. None of the above
Explanation:
The code defines a class Animal with an initializer that takes a name argument and a method speak() that does nothing. It also defines two subclasses Dog and Cat that override the speak() method and return the strings "Woof!" and "Meow!", respectively.
The Main block creates a Dog object myDog with the name "Buddy" and a Cat object myCat with the name "Fluffy". It then calls the speak() method on each object and prints a message indicating what the object says.
Therefore, the correct answer is option A) Buddy says Woof! Fluffy says Meow!. The output first shows the message printed by the myDog.speak() method, which is "Woof!", and then the message printed by the myCat.speak() method, which is "Meow!". Note that the name attribute is also printed for each object using the myDog.name and myCat.name expressions.
✅ A. Buddy says Woof! Fluffy says Meow!
❌ B. Buddy says Meow! Fluffy says Woof!
❌ C. Buddy says Woof! Fluffy says Woof!
❌ D. Buddy says Meow! Fluffy says Meow!
❌ E. Error
❌ F. None of the above
Explanation:
The code defines a class Animal with an initializer that takes a name argument and a method speak() that does nothing. It also defines two subclasses Dog and Cat that override the speak() method and return the strings "Woof!" and "Meow!", respectively.
The Main block creates a Dog object myDog with the name "Buddy" and a Cat object myCat with the name "Fluffy". It then calls the speak() method on each object and prints a message indicating what the object says.
Therefore, the correct answer is option A) Buddy says Woof! Fluffy says Meow!. The output first shows the message printed by the myDog.speak() method, which is "Woof!", and then the message printed by the myCat.speak() method, which is "Meow!". Note that the name attribute is also printed for each object using the myDog.name and myCat.name expressions.