Header Ads Widget

Responsive Advertisement

Python Programming Week 5 Quiz Solution [Python Programming course on Prutor.ai by IIT kharagpur]

Here you will get all the assignment and quiz solutions of Python Programming Course by prutor.ai. Prutor is an online smart tutoring platform which provides various MOOC courses for student and organised by by IIT Kharagpur. At the end of each course student gets a certificate for sucessfull  completion of each course but throughout the course students have to pass all the weekly assignments and quizes.


 [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

Answer: (d) Print all integers from 2 to n+1

[2]  What does the following Python3 code do? (using python 3.X version)

n = int(input(‘Enter a number?’))
i = 1
while i < n:
print (i)
i = i+1
  • (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

Answer: (b) Print all integers from 1 to n-1

[3] What does the following Python3 code do? (using python 3.X version)

n = int(input(‘Enter a number?’))
i = n
while i > 0 :
print (i);
i = i-1

  • (a): Print all integers from n to 1
  • (b): Print all integers from 1 to n
  • (c): Print all integers from n-1 to 1
  • (d): Print all integers from n-1 to 0

Answer: (a) Print all integers from n to 1

[4]  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

[5]  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




Answer:(c)  9, 36, 72, 72

[6]  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

[7]  The following code is supposed to read 5 inputs from the user and print the last input. It does not produce the desired answer. Why? (Select the choice that corresponds to the error having the simplest fix for the code.)(using python 3.X version)

inp = 5
while (inp > 0):
last = input(‘next num? ‘)
inp = inp + 1
print (last)

  • (a): The code works correctly
  • (b): Bad initialization: While loop variable
  • (c): Bad Update: Variable
  • (d): Bad Termination: The termination condition should be: inp > 10

Answer:(c) Bad Update: Variable

[8]  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 ???? for the code to work correctly? (using python 3.X version)

N = int(input(‘Enter N:’))
i = 1
while ( i < N ) :
print(i)
????

  • (a): i%2 == 1
  • (b): i = i + 2
  • (c): i = 1 + i * 2
  • (d): i = i * 2




Answer:(b) i = i + 2


If you have any quetions, please comment down below, we will try to answer with in first 24 hour. Hope you liked this content, We will come with another week’s quiz, Thanks for reading. Good Bye.

Post a Comment

0 Comments