Problem Solving and Python Programming MCQs | Page - 35
Dear candidates you will find MCQ questions of Problem Solving and Python Programming here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Explanation: the list comprehension [x for x in range(1000) if x%3==0] produces a list of numbers between 1 and 1000 that are divisible by 3.
Explanation: the required list comprehension will print the numbers from 1 to 12, each raised to 2. the required answer is thus, [(2**x) for x in range(0, 13)].
Explanation: the required list comprehension will print a whole number, less than 20, provided that the number is even. since the output list should contain zero as well, the answer to this question is: [x for x in range(0, 20) if (x%2==0)].
Explanation: the list comprehension shown above returns a list of non-prime numbers up to 50. the logic behind this is that the square root of 50 is almost equal to 7. hence all the multiples of 2-7 are not prime in this range.
Explanation: to get a particular column as output, we can simple iterate across the rows and pull out the desired column, or iterate through positions in rows and index as we go. hence the output of the code shown above is: [2, 5, 8].
Explanation: the code shown above shows a list comprehension which adds 10 to each element of the matrix a and prints it row- wise. hence the output of the code is: [[11, 12, 13], [14, 15, 16], [17, 18, 19]]
Jump to