Python Week 5 Quiz Answers
If you require any more information or you have any problem regarding Copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at contact@prutor-ai.com.
All the information on this website is published in good faith and for general information and educational purpose only. Prutor-ai does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website (Prutor-ai.blogspot.com), is strictly at your own risk. will not be liable for any losses and/or damages in connection with the use of our website.
In this students get weekly assignments that they have to complete every week. Here we will show you or give you all the answers for the python quiz, These answers are for all those who have confusion in the questions or they don’t want to submit wrong answers.
Q1. 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)
Ans: Print
all integers from 2 to n+1
Reason: As in the given
program i=1 when we assign the value or n in the program. The value may be
equal to 1 or greater than 1. When the value is equal to 1 while condition
execute and it will print 2. And when we assign 0 while condition while
condition does not execute and nothing will print. Hence the minimum value is 2
and if the value is greater than 1, the while condition execute till the condition
false hence it will continuously change the value of i and always print n+1
hence fourth option is correct.
Q2. 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)
Ans: 10
Reason: In the given program n=13 and sum=0, hence while
condition is true therefore it runs, when 12 divided by 2 produces 6 the sum= 6+0
then again it execute then it produce 3 which is added in sum, the sum become
9. Again while condition execute finally 3 decided by 2 it produces 1 which is
added in sum become 9+1=10.
Q3. 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))
Ans: 9
36
72
72
Reason: n,p= 9,1 hence (n>=1) while condition execute
by division of n and multiplication of it by p first produce 9 then 36 then 72
then 72.
Q4. 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 X for the code to work
correctly?(using python 3.X version):
N = int(input('Enter
N:'))
i = 1
while
( i < N ) :
if ( X ):
print(i)
i = i + 1
Ans: i%2==
0
Reason: The code should print all positive even number
less than or equal to N. N is taken as input from the user and it will take fourth
option as to print the desired output.
Q5. 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
Ans: i= i+2
Reason: The code should print all positive odd number
less than or equal to N. N is taken as input from the user and it will take second
option i.e., i= i+2 as to print the desired output.

Social Plugin