AKTU Python Programming 5th Week Quiz Solution



AKTU ICT Academy Python Programming a practical Approach 5th Week Quiz Solutions

Hey guys here are the solutions of AKTU ICT Academy Python quiz solutions for the first week. AKTU released noncredit courses for 2nd-year computer science students of B. Tech. The course code is KNC 301/KNC 302.


These answers are for all those who have confusion in the questions or they don’t want to submit wrong answers. Please attempt the quiz yourself before proceeding for the answers.

Disclaimer :- I don't claim for the 100% accuracy of the answers. I tried my level best to present the correct answers and I'm not responsible if any of the answer is incorrect.




[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:(b) Bad initialization: While loop 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
SHARE If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
Newer Posts Newer Posts Older Posts Older Posts

More posts

Comments

Post a Comment

Sponsored Content