Quiz on Switch
FREE Online Courses: Click for Success, Learn for Free - Start Now!
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
- Which of the following cannot be used to implement a switch in Python?
CorrectIncorrect -
Question 2 of 15
2. Question
- Choose the correct option about the working of a general switch case in Python.
CorrectIncorrect -
Question 3 of 15
3. Question
- Which of the following is true about the switch?
CorrectIncorrect -
Question 4 of 15
4. Question
What is the output of the following code?
def sign(num):
if(num>0):
print(“Positive”)
elif(num<0):
print(‘Negative’)
else:
print(‘Zero’)
sign(0)CorrectIncorrect -
Question 5 of 15
5. Question
- What is the use of the default case in the switch?
CorrectIncorrect -
Question 6 of 15
6. Question
Which of the following is the correct output for the following code?
def number(n):
switch={
1:’one’,
2:’two’,
3:’three’,
}
return switch.get(n,”No Output”)number(‘2’)
CorrectIncorrect -
Question 7 of 15
7. Question
What is the output of the following code?
def OddEve(num):
if(num%2):
return(“Odd”)
return(‘Even’)
OddEve(1)CorrectIncorrect -
Question 8 of 15
8. Question
- Which of the following is true about the switch over the if statements?
CorrectIncorrect -
Question 9 of 15
9. Question
What is the output of the following code?
a=5
b=6def add():
return a+bdef subs():
return a-bdef prod():
return a*bdef div():
return a//bdef operations(op):
switch={
‘a’: add(),
‘s’: subs(),
‘p’: prod(),
‘d’: div(),}
return switch.get(op,’Wrong input’)operations(‘P’)
CorrectIncorrect -
Question 10 of 15
10. Question
Which of the following is the correct output for the below code?
list1=[14,19,6,13,0]
def func(lst):
for i in lst:
if i%2:
print(i,end=’ ‘)
else: passfunc(list1)
CorrectIncorrect -
Question 11 of 15
11. Question
Which of the following is the correct way of using the class for the switch?
a.
class Class():
def case1():
print(‘Hello’)
def case2():
print(‘Hi’)
def case3():
print(‘Welcome’)
def cases(self,no):
func=”case”+str(no)
method=getattr(self,func,lambda :’Bye’)
return method()
obj=Class()
obj.cases(2)
b.
class Class():
def case1(self):
print(‘Hello’)
def case2(self):
print(‘Hi’)
def case3(self):
print(‘Welcome’)
def cases(self,no):
func=”case”+str(no)
method=getattr(self,func,lambda :’Bye’)
return method()
obj=Class()
obj.cases(2)
c.
class Class():
def case1(self):
print(‘Hello’)
def case2(self):
print(‘Hi’)
def case3(self):
print(‘Welcome’)
def cases(self,no):
func=”case”+(no)
method=getattr(self,func)
return method()
obj=Class()
obj.cases(2)
CorrectIncorrect -
Question 12 of 15
12. Question
What is the output of the following code?
def compare(a,b):
if(a>b):
return ‘a’
if(a<=b):
return ‘b’
return ‘None’compare(4,9)
CorrectIncorrect -
Question 13 of 15
13. Question
What could be the output of the following code?
def membership(ch,st):
switch={
True: ‘Present’,
False: ‘Not present’
}
return switch.get(ch in st,’Wrong input’)membership(1,154)
CorrectIncorrect -
Question 14 of 15
14. Question
Find the output of the following code.
def vowels(string):
switch={
‘a’: 1,
‘e’: 2,
‘i’: 3,
‘o’: 4,
‘u’: 5,
}
for i in string:
print(switch.get(i,””),end=””)vowels(‘abteci’)
CorrectIncorrect -
Question 15 of 15
15. Question
What is the output of the following code?
def fun1():
print(1)def fun2():
print(2)def fun3():
print(3)def func(ch):
switch={
‘x’: fun1,
‘y’: fun2,
‘z’: fun3,}
return switch.get(ch,’Wrong input’)print(func(‘z’))
CorrectIncorrect