Ad Code

Python Quiz 5 Answers 100% correct No UFM

 Programming for Noobs

PYTHON Quiz 5 Answers




Disclaimer-

This article only attempts to discover some questions that can be generated in Python for Engineering with the answer to all these questions. There can be some errors to these answers. If you find any error then please do write to us.


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)

1.Print all integers from 1 to n

2.Print all integers from 1 to n-1

3.Print all integers from 2 to n

4.Print all integers from 2 to n+1

Reason: option 4 will be correct because if we run this program we will get correct answer as per the 2 to n+1 or we can say option 4.

Programming for Noobs




Programming for Noobs

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)

1.13

2.10

3.6

4.9

Reason: As per the above commands or program we will get 10 or option 2 as the correct answer.

Programming for Noobs



Programming for Noobs

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))

1.8

2.102

3.9    
     36
     72
     72

4.Error

Reason:  As per the above commands or programs, we will get the option 3 or 9 36 72 72 as the correct answer.





Programming for Noobs

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

1.i//2 == 0

2.i%2! = 0

3.i//2! = 0

4.i%2 == 0

Reason:  if we replace X with i%2=0 we will get the desired output, so here option 4 is the correct answer.

Programming for Noobs




Programming for Noobs

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

1.i%2 == 1

2.i = i + 2

3.i = 1 + i * 2

4.i = i * 2

Reason: if we replace X with i=i+2 then we will get the desired output, so here option 2 is the correct answer.

Programming for Noobs

Please subscribe to our channel 








Post a Comment

0 Comments