Disclaimer for ReGyan
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 hello@regyan.com.
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
[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)
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
Also see: AICTSD (Albert Einstein International Scholarship Test )
Python Programming Quiz– 6th Solutions
Python programming quiz 6th solutions are given below:-
[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
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)
[2] 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
[3] 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 …
[4] 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
[5] 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
Answer(d) 320
[6] 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.
[7] Functions allow us to “divide and conquer” a complex programming task into simpler programming tasks.
- (a): True
- (b): False
Answer:(a) True
[8] Functions are the only way to write modular programs in Python.
- (a): True
- (b): False
Answer:(b) False
[9] 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.
[10]
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.
Also see: Python Quiz (Programming )– 4th Week Quiz Solution
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.
What will be the output of the following code :- i=5
def checkGlobal():
global i
i=i+10
print(i)
checkGlobal()
15
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)
7
9
3
What will be the output of the following code :-
i=5
def checkGlobal():
i=50
global i
i=i+10
print(i)
Error in the code
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
Global keyword allows user to modify variable outside of local scope
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)
9
What will be the output of following
x=10
y=20
def calculate ():
x=5
x=x*y
print(x)
calculate()
100
can you please explain , how it is executed
Find the output of the following
i=5
def Check global():
i=50
global i
i=i+10
print(i)
Error in the code
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)
7
9
3
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
both A and B
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
a function can be called only once in a program
What will be the output of the following code :-
str = “hello”
str = str+” ”
print(str*5)
hello hello hello hello hello
Find the output of the following:
str=”hello”
str=str+” ”
print(str*5)
hello hello hello hello hello
Find the output of the following:
x=10
y=20
def calculate():
x=x*y
print(x)
calculate()
Please see the comments
Both the questions are different.
Find the output of the following:
x=10
y=20
def calculate():
x=x*y
print(x)
calculate()
Error
Thank you
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
Either double quotes or single quotes can be used
I think answer is d
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
Either double quotes or single quotes can be used
Answer is d
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)
9
I think solution of Q9 & Q10 in quiz 6 are wrong.
Y3 is either second largest or the third largest
Y5 is largest.