Quiz on Python Switch Case
When we talk about life we have plenty of choices to make which decide our future ahead. Similarly, in python, we have an option of coding plenty of choices using the switch case. By using a switch case you can ponder upon the n possibilities and draw the required result.
Let us now test our knowledge through quiz on Switch case in Python.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
- Question 1 of 15
1. Question
Does python have a pre-defined switch-case syntax?
CorrectIncorrect - Question 2 of 15
2. Question
Which of the following is used in the python switch case?
CorrectIncorrect - Question 3 of 15
3. Question
When does the case of waterfall execution arise in switch-case?
CorrectIncorrect - Question 4 of 15
4. Question
Why do we use Default in switch-case?
CorrectIncorrect - Question 5 of 15
5. Question
Which of the following is required to stop all the cases from executing?
CorrectIncorrect - Question 6 of 15
6. Question
Predict the output of the code given below?
Code snippet starts
def switch(nums):
for num in nums:
if num%2==0:
print(num,end=” “)
else:
continue
nums = [34,90,87,45,32,67,50,71]
switch(nums)
# Code snippet ends
CorrectIncorrect - Question 7 of 15
7. Question
How many “0” appear in the result?
# Code snippet starts
def switchCase(nums):
for num in nums:
if num >=55:
print(num*2//5)
elif num < 35:
print(num*5//2)
elif num > 25 and num < 55:
print(num)
else:
print(“0”)
nums = [105,53,12,78,2]
switchCase(nums)
# Code snippet ends
CorrectIncorrect - Question 8 of 15
8. Question
Find the output of the code given below?
# Code snippet starts
options = { 0 : “zero”,
1 : “square”,
4 : “square”,
2 : “even”,
3 : “prime”,
7 : “prime”,
}
def zero():
print(“Zero”, end=” “)
def sqr():
print(“Square Number”, end=” “)
def even():
print(“Even Number”, end=” “)
def prime():
print(“Prime Number”,end=” “)
options[3]()
# Code snippet ends
CorrectIncorrect - Question 9 of 15
9. Question
Find the output of the code given below?
# Code snippet starts
def orgSort(org):
vowel = [‘a’,’e’,’i’,’o’,’u’]
spChar = [‘-‘,’&’,’@’,’#’,’&’]
org = org.lower()
count = 0
for e in org:
if e in vowel:
count+=10
elif e in spChar:
count+=50
elif e.isupper():
count+=100
else:
count-=5
return count
org = “#Quiz$Orbit@”
ans = orgSort(org)
print(ans)
# Code snippet ends
CorrectIncorrect - Question 10 of 15
10. Question
Find the output of the code given below?
# Code snippet starts
def calc(nums):
for i in nums:
if i == 50:
print(“half century”,end=”–“)
elif i == ‘100’:
print(“century”,end=”-“)
elif i == 200:
print(“Double Century”,end=” “)
nums = [0,100,200,75,50,200,100]
calc(nums)
# Code snippet ends
CorrectIncorrect - Question 11 of 15
11. Question
Find the output of the code given below?
# Code snippet starts
def calc(nums):
for i in nums:
if i == ’50’:
print(“half century”,end=”–“)
elif i == ‘100’:
print(“century”,end=”-“)
elif i == ‘200’:
print(“Double Century”,end=”–“)
else:
print(“Exit”)
break
nums = [100,200,75,50,200]
calc(nums)
# Code snippet ends
CorrectIncorrect - Question 12 of 15
12. Question
Find the output of the code given below?
# Code snippet starts
nums = [0,90,98,34,21,78 ,121,235]
for num in nums:
if num < 50:
if num%2 == 0 :
print(num+10 , end =” “)
else:
print(“-1″, end = ” “)
elif num >= 50 and num < 80 :
if (num*5//2)%3 == 0 :
print(“Ok”, end = ” “)
else:
print(“Fail”,end=” “)
elif num >= 80 and num < 200:
print(“Limit”, end =” “)
# Code snippet ends
CorrectIncorrect - Question 13 of 15
13. Question
Find the output of the code given below?
# Code snippet starts
def switchCase(org):
for l in org:
if ord(l)*2 >= 210:
print(l,end=”-“)
else:
continue
org = “QuizOrbit”
switchCase(org)
print(“a”,end=” “)
# Code snippet ends
CorrectIncorrect - Question 14 of 15
14. Question
How many “1” appear in the result of the code given below?
# Code snippet starts
def switchCase(nums):
for num in nums:
if num:
print(“0″,end=”1”)
else:
print(“-1”)
nums = [105,53,12,78,2]
switchCase(nums)
# Code snippet ends
CorrectIncorrect - Question 15 of 15
15. Question
What will be the output of the code given below?
# Code snippet starts
def switch(nums):
for num in nums:
if num:
print(num,end=” “)
else:
continue
nums = [34,90,87,45,32,67,50,71]
switch(nums)
# Code snippet ends
CorrectIncorrect
Summary
With the Quiz, you all might have got an essence of the possible problems which can be framed on the switch case in python. Switch case helps us make choices among plenty of options that we can get in our code. We recommend you move to the next quiz after clearing the concepts involved here. Happy Learning!