Python Quiz Solution 5 ( new 2021 )
Python Programming Quiz – 5th
Week Quiz Solution 2021 Aktu - Prutor
[1] What does the following Python3 code do? (using python 3.X version)
n = int(input(‘Enter a number?’))
i = 1
while i <= n:
i = i+1
print (i)
- (a): Print all integers from 1 to n
- (b): Print all integers from 1 to n-1
- (c): Print all integers from 2 to n
- (d): Print all integers from 2 to n+1
[2] What will the output of the following Python3 program (using python 3.X version)?
n = 13
sum = 0
while (n > 1):
n = n//2
sum = sum + n
print(sum)
- (a): 13
- (b): 10
- (c): 6
- (d): 9
Answer: (b) 10
Reason:-the output of the following Python3 program (using python 3.X version) , so i know that Python 3 is more consistent language. Python 3 is the present and future of the language. and i run this code and the output of 10 ,
[3] What will the output of the following Python3 program? If the program has error, select the option ERROR (using python 3.X version)
n,p = 9,1
while (n >= 1):
n,p = n//2,n*p
print(int(p))
- (a): 8
- (b): 102
- (c): 9, 36, 72, 72
- (d): Error
[4] The following code should print all positive even numbers less than or equal to N. N is taken as input from the user. What should replace the ???? for the code to work correctly?(using python 3.X version)
N = int(input(‘Enter N:’))
i = 1
while ( i < N ) :
if ( ???? ):
print(i)
i = i + 1
- (a): i//2 == 0
- (b): i%2 != 0
- (c): i//2 != 0
- (d): i%2 == 0
Answer: (d) i%2 == 0
Reason:- when the following code should print all positive even numbers less than or equal to N. N is taken as input from the user. i%2 == 0 should replace the code for the code to work correctly (using python 3.X version) , because it is while & if statement .
[5] The following code should print all positive odd numbers less than or equal to N. N is taken as input from the user. What should replace the X for the code to work correctly? (using python 3.X version)
N = int(input(‘Enter N:’))
i = 1
while ( i < N ) :
print(i)
X
- (a): i%2 == 1
- (b): i = i + 2
- (c): i = 1 + i * 2
- (d): i = i * 2
0 Comments