General Python Quiz 2
Answer : C
Explanation
If the string is not found by method find() , it returns the integer -1.
Answer : A
Explanation
z = z++ is not valid in python, it is not a legal expression. It results in syntax error.
Answer : B
Explanation
‘=‘ operator is right associative as assignment operators are right associative.
Q 14 - What is output of following code −
def func(x, ans): if(x==0): return 0 else: return func(x-1, x+ans) print(func(2,0))
Answer : A
Q 15 - What command is used to shuffle a list ‘L’?
Answer : D
Explanation
To shuffle the list we use random.shuffle(List_name) function.
Q 16 - Guess the output −
def main(): try: func() print(''print this after function call'') except ZeroDivisionError: print('Divided By Zero! Not Possible! ') except: print('Its an Exception!') def func(): print(1/0) main()
B ) ‘Divided By Zero! Not possible!’
C ) ‘print this after function call’ followed by ‘Divided By Zero! Not Possible!’
D ) ‘print this after function call’ followed by ‘Its an Exception!’
Answer : B
Explanation
The function ‘func’ will not run because it contains an exception. So in try and expect block. The function called under try will not run and will move to except block which defines the type of exception present in the function ‘func’. Thus block of statements present in except ZeroDivisionError is printed.
Q 17 - Which among them will produce {'a', 'b', 'c'}?
Answer : D
Explanation
Set does not allow the repetitive values in it and it separated each value present under a string.
Q 18 - Select the correct code to create a check button under parent frame1 and it should be bind to v1?
A ) CheckButton(frame1, text=''Bold'' , command=CheckButton)
B ) Checkbutton(frame1 , text=''Bold’’ ,variable=v1 ,command=processCheckbutton)
C ) Checkbutton(frame1,text=''Bold'',variable=v1.set(),command=v1.set(processCheckbut ton)
D ) Checkbutton(frame.set(f1) ,text.set(''bold'') ,command=v1.set(processCheckbutton)
Answer : B
Explanation
Checkbutton method is used to make a checkbox. In the parameters we need to pass the values as asked in the question. Here it should bind to v1 thus variable is set to v1 and frame should be under frame1 thus frame1 mentioned in the code.
Q 19 - Which way among them is used to create an event loop ?
Answer : B
Q 20 - What is the value of a, b, c in the given below code?
a, b = c = 2 + 2, ''SenGideons''
b= 4, 'SenGideons'
c= 4, 'SenGideons'
b= 'SenGideons'
c=4, 'SenGideons'
b= 'SenGideons'
c=4, 'SenGideons'
b= 'SenGideons'
c= NULL.
0 Comments