0 of 15 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
You must sign in or sign up to start the quiz.
You must first complete the following:
Quiz complete. Results are being recorded.
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 )
Show Question
1
Show Question
2
Show Question
3
Show Question
4
Show Question
5
Show Question
6
Show Question
7
Show Question
8
Show Question
9
Show Question
10
Show Question
11
Show Question
12
Show Question
13
Show Question
14
Show Question
15
Review / Skip
Answered
Correct
Incorrect
Question 1 of 15
Which of the following cannot be used to implement a switch in Python?
Question 2 of 15
Choose the correct option about the working of a general switch case in Python.
Question 3 of 15
Which of the following is true about the switch?
Question 4 of 15
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)
Question 5 of 15
What is the use of the default case in the switch?
Question 6 of 15
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’)
Question 7 of 15
What is the output of the following code?
def OddEve(num): if(num%2): return(“Odd”) return(‘Even’) OddEve(1)
Question 8 of 15
Which of the following is true about the switch over the if statements?
Question 9 of 15
What is the output of the following code?
a=5 b=6
def add(): return a+b
def subs(): return a-b
def prod(): return a*b
def div(): return a//b
def operations(op): switch={ ‘a’: add(), ‘s’: subs(), ‘p’: prod(), ‘d’: div(),
} return switch.get(op,’Wrong input’)
operations(‘P’)
Question 10 of 15
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: pass
func(list1)
Question 11 of 15
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)
Question 12 of 15
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)
Question 13 of 15
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)
Question 14 of 15
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’)
Question 15 of 15
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’))