# Python Programming Quiz – 5th&6th Week Quiz Solution

40
2670

## Disclaimer for ReGyan

### Disclaimers for ReGyan

All the information on this website is published in good faith and for general information and educational purpose only. ReGyan 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 (regyan.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.

### Python Programming Quiz– 5th Solutions

 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

  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

 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

  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

  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

  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

  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
• (d): Bad Termination: The termination condition should be: inp > 10

  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

### Python Programming Quiz– 6th Solutions

Python programming quiz 6th solutions are given below:-

  What is the output of the following Python3 program (using python 3.X version):

i = 1

while i <= 10:

if i%2==0: # even

continue

print (i, end=’ ‘)

i= i+1

• (a): 1 3 5 7 9
• (b): 2 4 6 8 10
• (c): The program will go into an infinite loop, printing 1 1 1 …
• (d): The program will go into an infinite loop (after possibly printing a single 1)

Answer:(d) The program will go into an infinite loop (after possibly printing a single 1)

 What is the output of the following Python3 program (using python 3.X version):

i = 1

while i <= 10:

i= i+1

if i%2==0: # even

continue

print (i, end=’ ‘)

• (a): 3 5 7 9 11
• (b): 1 3 5 7 9
• (c): The program will go into an infinite loop, printing 1 1 1 …
• (d): The program will go into an infinite loop, printing nothing

Answer:(a) 3 5 7 9 11

 What is the output of the following Python3 program (using python 3.X version):

i = 1

while i <= 10:

if i%2==0: # even

i= i+1

continue

print (i, end=’ ‘)

• (a): 3 5 7 9 11
• (b): 1 3 5 7 9
• (c): The program will go into an infinite loop, printing 1 1 1 …
• (d): The program will go into an infinite loop, printing nothing

Answer: (c) The program will go into an infinite loop, printing 1 1 1 …

 What is the output of the following Python3 program (using python 3.X version):

i = 1

while i <= 10:

if i%2==0: # even

i= i+1

continue

print (i, end=’ ‘)

i= i+1

• (a): 3 5 7 9 11
• (b): 1 3 5 7 9
• (c): The program will go into an infinite loop, printing 1 1 1 …
• (d): The program will go into an infinite loop, printing nothing

Answer:(b) 1 3 5 7 9

 What is the output of the following program (using python 3.X version):

r,a,n = 2,10,20

term = a

for i in range(n):

term = term * r

if (i > 3):

break

print (term)

• (a): 40
• (b): 80
• (c): 160
• (d): 320

 Which of the following statements is NOT true about Python functions:

• (a): A function can be called only once in a program.
• (b): A function allows us to break a program into small, independent tasks.
• (c): A function can call other functions.
• (d): Python provides several helpful functions

Answer:(a) A function can be called only once in a program.

 Functions allow us to “divide and conquer” a complex programming task into simpler programming tasks.

• (a): True
• (b): False

  Functions are the only way to write modular programs in Python.

• (a): True
• (b): False

 Assume that the “min” function computes the minimum of two values, and “max” function computes the maximum of two values. Let x1, x2, x3 and x4 be 4 distinct integers. What can you say about the following program (using python 3.X version):

y1 = min(x1, x2)

y2 = min(x3, x4)

y3 = max(y1, y2)

• (a): y3 is the largest integer among x1, x2, x3, x4.
• (b): y3 is either the largest or the second largest integer among x1, x2, x3, x4.
• (c): y3 is either the second largest or the third largest integer among x1, x2, x3, x4.
• (d): y3 is the third largest integer among x1, x2, x3, x4.

Answer: (a)  y3 is the largest integer among x1, x2, x3, x4.



#### Assume that the “min” function computes the minimum of two values, and “max” function computes the maximum of two values. Let x1, x2, x3 and x4 be 4 distinct integers. What can you say about the following program (using python 3.X version):

y1 = min(x1, x2)

y2 = min(x3, x4)

y3 = x1 + x2 – y1

y4 = x3 + x4 – y2

y5 = max(y3, y4)

• (a): y5 is the largest integer among x1, x2, x3, x4.
• (b): y5 is either the largest or the second largest integer among x1, x2, x3, x4.
• (c): y5 is either the second largest or the third largest integer among x1, x2, x3, x4.
• (d): Can not say anything as the data is not sufficient.

Answer:(c) y5 is either the second largest or the third largest integer among x1, x2, x3, x4.

That’s all for the Python programming Quiz – 5th&6th Week Quiz Solution. if you have any questions, please comment down below, we will try to answer within the first 24 hours. I hope you liked this content. We will come to another week’s quiz. Thanks for reading.

1. aman shukla

What will be the output of the following code :- i=5
def checkGlobal():
global i
i=i+10
print(i)
checkGlobal()

• admin

15

2. Prince

What will be the output of the following code
def func_default(x=1, y=2, z=3)
Print(x)
Print(y)
Print(z)
func_default(7,9)

• admin

7
9
3

3. ANUJ KUMAR PANDEY

What will be the output of the following code :-
i=5
def checkGlobal():
i=50
global i
i=i+10
print(i)

• admin

Error in the code

4. Alis Kadiyan

Which of the following is true for global keyword
1. Global keyword allows user to modify variable outside of local scope

2. It is required to use global keyword outside a function

3. Both a and b

4. None of the above

• admin

Global keyword allows user to modify variable outside of local scope

5. Sunita Bajpai

What will be the output of the following
def func=keyword(x=1,y=2,z=3):
sum=x+y
min=sum-z
print(min)
func_keyword(y=8,x=4)

• admin

9

6. Sunita Bajpai

What will be the output of following
x=10
y=20
def calculate ():
x=5
x=x*y
print(x)
calculate()

• admin

100

• Abhishek

can you please explain , how it is executed

7. Akriti Marwah

Find the output of the following
i=5
def Check global():
i=50
global i
i=i+10
print(i)

• admin

Error in the code

8. Rupesh Singh

Find the output of the following
def func_default(x=1, y=2, z=3)
print(x)
print(y)
print(z)
find_default(7,9)

• admin

7
9
3

9. Komal sonii

which of the following is ture for default keyboard?
A. if a argument is not supplied in the function call,default value is used.
B. order does not matter for default and non default in a function defination.
C. both A and B
D. none of the above

• admin

both A and B

10. Suman Chaurasia

Which of the following statement is not true about Python functions:
a) a function can be called only once in a program
b) a function allows us to break a program into small independent tasks
c) a function can call other functions
d) Python provides several helpful functions

• admin

a function can be called only once in a program

11. Komal soni

What will be the output of the following code :-
str = “hello”
str = str+” ”
print(str*5)

• admin

hello hello hello hello hello

12. Sudhiksha Yadav

Find the output of the following:
str=”hello”
str=str+” ”
print(str*5)

• admin

hello hello hello hello hello

13. Sumegha Singh

Find the output of the following:
x=10
y=20
def calculate():
x=x*y
print(x)
calculate()

• admin

• Sumegha Singh

Both the questions are different.

• Raghav Dubey

Find the output of the following:
x=10
y=20
def calculate():
x=x*y
print(x)
calculate()

• admin

Error

14. Raghav Dubey

Thank you

15. Rupali Bhatt

Which is true for string in Python?
a) they represent sequence of characters
b) either double quotes or single quotes can be used
c)Backslash can be used to escape quote
d) all of the above

• admin

Either double quotes or single quotes can be used

• Abhishek

16. Shivangi chaurasia

Which is true for string in Python?
a) they represent sequence of characters
b)Either double quotes or single quotes can be used
c) Backslash can be used to escape the quote
d) all of the above

• admin

Either double quotes or single quotes can be used

• Abhishek

17. Shubhangi

What will be the output of the following code:-
def func_keyword(x=1, y=2, z=3):
sum = x+y
min = sum – z
print (min)
func_keyword(y=8,x=4)

• admin

9

18. Abhishek

I think solution of Q9 & Q10 in quiz 6 are wrong.
Y3 is either second largest or the third largest
Y5 is largest.