python quiz

Python Control Structures Online Quiz

python quiz

Test your coding prowess in our Ultimate Programming Python Control Structures Online Quiz with Total 10 Questions.

Whether you're a seasoned developer or just dipping your toes into the programming world, challenge yourself with a range of questions spanning languages like Python, Java, and more.

Are you ready to conquer the coding conundrums? Put on your thinking hat and dive into the quiz now!

Name
Email
1. 
Which of the following is not used as loop in Python?

2. 
What will be the output of given Python code?

n=7
c=0
while(n):
Β  Β  if(n>5):
Β  Β  Β  Β  c=c+n-1
Β  Β  Β  Β  n=n-1
Β  Β  else:
Β  Β  Β  Β  break
print(n)
print(c)
Β 

3. 
Which of the following Python code will give different output from the others?

4. 
What keyword would you use to add an alternative condition to an if statement?

5. 
Can we write if/else into one line in python?

6. 
What will be output of this expression:

'p' + 'q' if '12'.isdigit() else 'r' + 's'

7. 
What will be the output of the following code?

list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
sum1 = 0
for elem in list1:
Β  Β  if (elem % 2 == 0):
Β  Β  Β  Β  sum = sum + elem
Β  Β  Β  Β  continue

Β  Β  if (elem % 3 == 0):
Β  Β  Β  Β  sum1 = sum1 + elem
Β 
print(sum , end=" ")
print(sum1)

8. 
What is the value of the var after the for loop completes its execution?

var = 10
for i in range(10):
Β  Β  for j in range(2, 10, 1):
Β  Β  Β  Β  if var % 2 == 0:
Β  Β  Β  Β  Β  Β  continue
Β  Β  Β  Β  Β  Β  var += 1
Β  Β  var+=1
else:
Β  Β  var+=1
print(var)

9. 
What is the output of the following nested loop ?

numbers = [10, 20]
items = ["Chair", "Table"]
Β 
for x in numbers:
Β  for y in items:
Β  Β  print(x, y)

10. 
Which statement will check if a is equal to b?