-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyQuestions.json
1625 lines (1400 loc) · 47.2 KB
/
pyQuestions.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[
{
"id": "1",
"category" : "Variable Names",
"instruction" : "Is Python case sensitive when dealing with identifiers?" ,
"expression" : "" ,
"correct": "yes",
"options": [
"no",
"machine dependent",
"yes",
"none of the mentioned"
],
"Explanation" : "Case is always significant."
},
{
"id": "2",
"category" : "Variable Names",
"instruction" : " What is the maximum possible length of an identifier?" ,
"expression" : "" ,
"correct": "none of the mentioned",
"options": [
"none of the mentioned",
" 31 characters",
" 63 characters",
"79 characters"
],
"Explanation" : " Identifiers can be of any length."
},
{
"id": "3",
"category" : "Variable Names",
"instruction" : "Which of the following is invalid?" ,
"expression" : "" ,
"correct": "none of the mentioned",
"options": [
"_a = 1",
" __a = 1",
" __str__ = 1",
"none of the mentioned"
],
"Explanation" : "All the statements will execute successfully but at the cost of reduced readability."
},
{
"id": "4",
"category" : "Variable Names",
"instruction" : " Which of the following is an invalid variable?" ,
"expression" : "" ,
"correct": "1st_string",
"options": [
"1st_string",
" my_string_1",
"foo",
" _"
],
"Explanation" : " Variable names should not start with a number."
},
{
"id": "5",
"category" : "Variable Names",
"instruction" : "Why are local variable names beginning with an underscore discouraged?" ,
"expression" : "" ,
"correct": "they are used to indicate a private variables of a class",
"options": [
" they confuse the interpreter",
"they are used to indicate a private variables of a class",
" they are used to indicate global variables",
" they slow down execution"
],
"Explanation" : " As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class."
},
{
"id": "6",
"category" : "Variable Names",
"instruction" : " Which of the following is not a keyword?" ,
"expression" : "" ,
"correct": "eval",
"options": [
" assert",
"nonlocal",
"pass",
"eval"
],
"Explanation" : "eval can be used as a variable."
},
{
"id": "7",
"category" : "Variable Names",
"instruction" : "All keywords in Python are in _________" ,
"expression" : "" ,
"correct": "None of the mentioned",
"options": [
"lower case",
"UPPER CASE",
"Capitalized",
" None of the mentioned"
],
"Explanation" : "True, False and None are capitalized while the others are in lower case."
},
{
"id": "8",
"category" : "Variable Names",
"instruction" : " Which of the following is true for variable names in Python?" ,
"expression" : "" ,
"correct": " unlimited length",
"options": [
" unlimited length",
" all private members must have leading and trailing underscores",
"underscore and ampersand are the only two special characters allowed",
" none of the mentioned"
],
"Explanation" : " Variable names can be of any length."
},
{
"id": "9",
"category" : "Variable Names",
"instruction" : "Which of the following is an invalid statement?" ,
"expression" : "" ,
"correct": "a b c = 1000 2000 3000",
"options": [
" abc = 1,000,000",
"a b c = 1000 2000 3000",
"a,b,c = 1000, 2000, 3000",
" a_b_c = 1,000,000"
],
"Explanation" : "Spaces are not allowed in variable names."
},
{
"id": "10",
"category" : "Variable Names",
"instruction" : " Which of the following cannot be a variable?" ,
"expression" : "" ,
"correct": "in",
"options": [
"__init__",
"in",
"it",
"on"
],
"Explanation" : "in is a keyword."
},
{
"id": "11",
"category" : "Basic Operators",
"instruction" : "Which is the correct operator for power(xy)?" ,
"expression" : "" ,
"correct": "X**y",
"options": [
"X^y",
"X^^y",
"X**y",
"None of the mentioned"
],
"Explanation" : " In python, power operator is x**y i.e. 2**3=8."
},
{
"id": "12",
"category" : "Basic Operators",
"instruction" : "Which one of these is floor division?" ,
"expression" : "" ,
"correct": "//",
"options": [
"/",
" %",
"//",
"None of the mentioned"
],
"Explanation" : "When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5 answer, use floor division."
},
{ "id":"13",
"category" : "Basic Operators",
"instruction" : "What is the order of precedence in python?" ,
"expression" : "i)Parentheses ii) Exponential iii) Multiplication iv) Division v) Addition vi) Subtraction" ,
"correct": "i,ii,iii,iv,v,vi",
"options": [
"ii,i,iii,iv,v,vi",
" ii,i,iv,iii,v,vi",
"i,ii,iii,iv,v,vi",
"i,ii,iii,iv,vi,v"
],
"Explanation" : "For order of precedence, just remember this PEMDAS (similar to BODMAS)."
},
{
"id":"14",
"category" : "Basic Operators",
"instruction" : "What is the answer to this expression, 22 % 3 is?" ,
"expression" : "" ,
"correct": "1",
"options": [
"7",
"0",
"5",
"1"
],
"Explanation" : " Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1."
},
{
"id":"15",
"category" : "Basic Operators TF",
"instruction" : "Mathematical operations can be performed on a string." ,
"expression" : "" ,
"correct": " False",
"options": [
"True",
" False",
"",
""
],
"Explanation" : " You can’t perform mathematical operation on string even if the string is in the form: ‘1234…’."
},
{
"id":"16",
"category" : "Basic Operators",
"instruction" : "Operators with the same precedence are evaluated in which manner?" ,
"expression" : "" ,
"correct": "Left to Right",
"options": [
"Right to Left",
"Left to Right",
"Can’t say",
"None of the mentioned"
],
"Explanation" : "None."
},
{
"id":"17",
"category" : "Basic Operators",
"instruction" : "What is the output of this expression, 3*1**3?" ,
"expression" : "" ,
"correct": "3",
"options": [
"27",
"9",
"3",
" 1"
],
"Explanation" : "First this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3."
},
{
"id":"18",
"category" : "Basic Operators",
"instruction" : "Which one of the following has the same precedence level?" ,
"expression" : "" ,
"correct": "Addition and Subtraction",
"options": [
"Multiplication, Division and Addition",
"Multiplication, Division, Addition and Subtraction",
"Addition and Subtraction",
" Addition and Multiplication"
],
"Explanation" : "“Addition and Subtraction” are at the same precedence level. Similarly, “Multiplication and Division” are at the same precedence level. However, Multiplication and Division operators are at a higher precedence level than Addition and Subtraction operators."
},
{
"id":"19",
"category" : "Basic Operators TF",
"instruction" : "he expression Int(x) implies that the variable x is converted to integer." ,
"expression" : "" ,
"correct": "True",
"options": [
"True",
"False"
],
"Explanation" : "None."
},
{
"id":"20",
"category" : "Basic Operators",
"instruction" : "Which one of the following has the highest precedence in the expression?" ,
"expression" : "" ,
"correct": "Parentheses",
"options": [
"Addition",
"Multiplication",
"Exponential",
"Parentheses"
],
"Explanation" : "Just remember: PEMDAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction. Note that the precedence order of Division and Multiplication is the same. Likewise, the order of Addition and Subtraction is also the same."
},
{
"id":"21",
"category" : "Core Data types",
"instruction" : "Which of these in not a core data type?" ,
"expression" : "" ,
"correct": "Class",
"options": [
" Lists",
"Dictionary",
"Tuples",
"Class"
],
"Explanation" : "Class is a user defined data type."
},
{ "id":"22",
"category" : "Core Data types",
"instruction" : "Given a function that does not return any value, What value is thrown by default when executed in shell." ,
"expression" : "" ,
"correct": "None",
"options": [
"int",
"bool",
"void",
"None"
],
"Explanation" : "Python shell throws a NoneType object back."
},
{ "id":"23",
"category" : "Core Data types",
"instruction" : "What will be the output of the following Python code?" ,
"expression" : ">>>str=\"hello\" >>>str[:2] >>>" ,
"correct": "he",
"options": [
"he",
" lo",
"olleh",
"hello"
],
"Explanation" : " We are printing only the 1st two bytes of string and hence the answer is “he”."
},
{ "id":"24",
"category" : "Core Data types",
"instruction" : "Which of the following will run without errors?" ,
"expression" : "" ,
"correct": "round(45.8)",
"options": [
" round(6352.898,2,5)",
"round(45.8)",
" round()",
"round(7463.123,2,1)"
],
"Explanation" : "Execute help(round) in the shell to get details of the parameters that are passed into the round function."
},
{ "id":"25",
"category" : "Core Data types",
"instruction" : "What is the return type of function id?" ,
"expression" : "" ,
"correct": "int",
"options": [
"int",
"float",
"bool",
"dict",
""
],
"Explanation" : "Execute help(id) to find out details in python shell.id returns a integer value that is unique."
},
{ "id":"26",
"category" : "Core Data types",
"instruction" : "n python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed." ,
"expression" : ">>>x = 13 ? 2 objective is to make sure x has a integer value, select all that apply (python 3.xx)" ,
"correct": "All of the mentioned",
"options": [
" 13 // 2",
" int(13 / 2)",
" 13 % 2",
"All of the mentioned"
],
"Explanation" : "// is integer operation in python 3.0 and int(..) is a type cast operator."
},
{ "id":"27",
"category" : "Core Data types",
"instruction" : "What error occurs when you execute the following Python code snippet?" ,
"expression" : "apple = mango" ,
"correct": "NameError",
"options": [
"SyntaxError",
"ValueError",
"NameError",
" TypeError"
],
"Explanation" : "Mango is not defined hence name error."
},
{ "id":"28",
"category" : "Core Data types",
"instruction" : "What will be the output of the following Python code snippet?" ,
"expression" : "def example(a): a = a + '2' a = a*2 return >>>example(\"hello\")" ,
"correct": "indentation Error",
"options": [
"cannot perform mathematical operation on strings",
"indentation Error",
" hello2",
" hello2hello2"
],
"Explanation" : "Python codes have to be indented properly."
},
{ "id":"29",
"category" : "Core Data types",
"instruction" : "What data type is the object below?" ,
"expression" : "L = [1, 23, 'hello', 1]" ,
"correct": "list",
"options": [
"list",
"dictionary",
"array",
"tuple"
],
"Explanation" : "List data type can store any values within it."
},
{ "id":"30",
"category" : "Core Data types",
"instruction" : "In order to store values in terms of key and value we use what core data type." ,
"expression" : "" ,
"correct": "dictionary",
"options": [
"list",
" tuple",
"dictionary",
"class"
],
"Explanation" : "Dictionary stores values in terms of keys and values."
},
{ "id":"31",
"category" : "Numeric Types",
"instruction" : "What is the output of print 0.1 + 0.2 == 0.3?" ,
"expression" : "" ,
"correct": "False",
"options": [
"True",
"False",
"Machine dependent",
" Error"
],
"Explanation" : "Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3."
},
{ "id":"32",
"category" : "Numeric Types",
"instruction" : "Which of the following is not a complex number?" ,
"expression" : "" ,
"correct": "k = 2 + 3l",
"options": [
"k = 2 + 3J",
"k = complex(2, 3)",
"k = 2 + 3l",
" k = 2 + 3j"
],
"Explanation" : "l (or L) stands for long."
},
{ "id":"33",
"category" : "Numeric Types",
"instruction" : "What is the type of inf?" ,
"expression" : "" ,
"correct": "Float",
"options": [
"Boolean",
"Integer",
"Complex",
"Float"
],
"Explanation" : "Infinity is a special case of floating point numbers. It can be obtained by float(‘inf’)."
},
{ "id":"34",
"category" : "Numeric Types",
"instruction" : "What does ~4 evaluate to?" ,
"expression" : "" ,
"correct": "-5",
"options": [
"-5",
"-4",
" -3",
" +3"
],
"Explanation" : " ~x is equivalent to -(x+1)."
},
{ "id":"35",
"category" : "Numeric Types",
"instruction" : "What does ~~~~~~5 evaluate to?" ,
"expression" : "" ,
"correct": "+5",
"options": [
"-11",
"+11",
"-5",
"+5"
],
"Explanation" : "~x is equivalent to -(x+1)."
},
{ "id":"36",
"category" : "Numeric Types",
"instruction" : "Which of the following is incorrect?" ,
"expression" : "" ,
"correct": "03964",
"options": [
"0b101",
"0x4f5",
"03964",
"19023"
],
"Explanation" : "Numbers starting with a 0 are octal numbers but 9 isn’t allowed in octal numbers."
},
{ "id":"37",
"category" : "Numeric Types",
"instruction" : "What is the result of cmp(3, 1)?" ,
"expression" : "" ,
"correct": "1",
"options": [
"0",
"1",
"True",
"False"
],
"Explanation" : "cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y."
},
{ "id":"38",
"category" : "Numeric Types",
"instruction" : "cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y." ,
"expression" : "" ,
"correct": "float(’12+34′)",
"options": [
"float(‘inf’) ",
"float(‘nan’)",
" float(’56’+’78’)",
"float(’12+34′)"
],
"Explanation" : " ‘+’ cannot be converted to a float."
},
{ "id":"39",
"category" : " Numeric Types",
"instruction" : "What is the result of round(0.5) – round(-0.5)?" ,
"expression" : "" ,
"correct": "Value depends on Python version",
"options": [
"1.0",
"2.0",
" 0.0",
"Value depends on Python version"
],
"Explanation" : "The behavior of the round() function is different in Python 2 and Python 3. In Python 2, it rounds off numbers away from 0 when the number to be rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1 whereas in Python 3, it rounds off numbers towards nearest even number when the number to be rounded off is exactly halfway through. See the below output. \n Here’s the runtime output for Python version 2.7 interpreter.6 \n $ python \n \n Python 2.7.17 (default, Nov 7 2019, 10:07:09) \n >>> round(0.5) \n 1.0 \n>>> round(-0.5) \n -1.0 \n>>> \nIn the above output, you can see that the round() functions on 0.5 and -0.5 are moving away from 0 and hence “round(0.5) – (round(-0.5)) = 1 – (-1) = 2” \n\nHere’s the runtime output for Python version 3.6 interpreter. \n\n $ python3 \nPython 3.6.8 (default, Oct 7 2019, 12:59:55) \n >>> round(0.5) \n 0 \n >>> round(-0.5) \n 0 \n>>> round(2.5) \n 2 \n >>> round(3.5) \n 4 \n >>> \n In the above output, you can see that the round() functions on 0.5 and -0.5 are moving towards 0 and hence “round(0.5) – (round(-0.5)) = 0 – 0 = 0“. Also note that the round(2.5) is 2 (which is an even number) whereas round(3.5) is 4 (which is an even number)."
},
{ "id":"40",
"category" : "Numeric Types",
"instruction" : "What does 3 ^ 4 evaluate to?" ,
"expression" : "" ,
"correct": "7",
"options": [
"81",
" 12",
"7",
"0.75"
],
"Explanation" : ": ^ is the Binary XOR operator."
},
{ "id":"41",
"category" : "Precedence and Associativity –1 TF",
"instruction" : "The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same." ,
"expression" : "" ,
"correct": "True",
"options": [
"False"
],
"Explanation" : "Although the presence of parenthesis does affect the order of precedence, in the case shown above, it is not making a difference. The result of both of these expressions is 1.333333333. Hence the statement is true."
},
{
"id":"42",
"category" : "Precedence and Associativity – 1",
"instruction" : "What will be the value of the following Python expression?" ,
"expression" : "4 + 3 % 5" ,
"correct": " 7",
"options": [
" 7",
" 4",
"2",
" 0"
],
"Explanation" : "The order of precedence is: %, +. Hence the expression above, on simplification results in 4 + 3 = 7. Hence the result is 7."
},
{
"id":"43",
"category" : "Precedence and Associativity – 1",
"instruction" : "Evaluate the expression given below if A = 16 and B = 15." ,
"expression" : "A % B // A" ,
"correct": "0",
"options": [
"0.0",
"1.0",
"0",
"1"
],
"Explanation" : "The above expression is evaluated as: 16%15//16, which is equal to 1//16, which results in 0."
},
{
"id":"44",
"category" : "Precedence and Associativity – 1",
"instruction" : "Which of the following operators has its associativity from right to left?" ,
"expression" : "" ,
"correct": "**",
"options": [
"+",
"//",
" %",
"**"
],
"Explanation" : "All of the operators shown above have associativity from left to right, except exponentiation operator (**) which has its associativity from right to left."
},
{
"id":"45",
"category" : "Precedence and Associativity – 1",
"instruction" : "What will be the value of x in the following Python expression?" ,
"expression" : "x = int(43.55+2/2)" ,
"correct": "44",
"options": [
"22",
" 23",
"43",
"44"
],
"Explanation" : "The expression shown above is an example of explicit conversion. It is evaluated as int(43.55+1) = int(44.55) = 44. Hence the result of this expression is 44."
},
{
"id":"46",
"category" : "Precedence and Associativity – 1",
"instruction" : "What is the value of the following expression?" ,
"expression" : "2+4.00, 2**4.0" ,
"correct": "(6.0, 16.0)",
"options": [
"(6.00, 16.00)",
" (6, 16)",
" (6.00, 16.0)",
"(6.0, 16.0)"
],
"Explanation" : " The result of the expression shown above is (6.0, 16.0). This is because the result is automatically rounded off to one decimal place."
},
{
"id":"47",
"category" : "Precedence and Associativity – 1",
"instruction" : "Which of the following is the truncation division operator?" ,
"expression" : "" ,
"correct": "//",
"options": [
" /",
"//",
"%",
"|"
],
"Explanation" : "// is the operator for truncation division. It is called so because it returns only the integer part of the quotient, truncating the decimal part. For example: 20//3 = 6."
},
{
"id":"48",
"category" : "Precedence and Associativity – 1",
"instruction" : "What are the values of the following Python expressions?" ,
"expression" : " 2**(3**2) (2**3)**2 2**3**2" ,
"correct": "512, 64, 512",
"options": [
" 64, 512, 64",
"64, 64, 64",
"512, 64, 512",
" 512, 512, 512"
],
"Explanation" : "Expression 1 is evaluated as: 2**9, which is equal to 512. Expression 2 is evaluated as 8**2, which is equal to 64. The last expression is evaluated as 2**(3**2). This is because the associativity of ** operator is from right to left. Hence the result of the third expression is 512."
},
{
"id":"49",
"category" : " Precedence and Associativity – 1",
"instruction" : "What is the value of the following expression" ,
"expression" : "8/4/2, 8/(4/2)" ,
"correct": "(1.0, 4.0)",
"options": [
" (1.0, 1.0)",
"(1.0, 4.0)",
" (4.0. 1.0)",
"(4.0, 4.0)"
],
"Explanation" : "The above expressions are evaluated as: 2/2, 8/2, which is equal to (1.0, 4.0)."
},
{
"id":"50",
"category" : "Precedence and Associativity – 1",
"instruction" : "What is the value of the following expression?" ,
"expression" : "float(22//3+3/3)" ,
"correct": "8.0",
"options": [
"8",
"8.0",
"8.3",
"8.33"
],
"Explanation" : "The expression shown above is evaluated as: float( 7+1) = float(8) = 8.0. Hence the result of this expression is 8.0."
},
{
"id":"51",
"category" : "Precedence and Associativity – 2",
"instruction" : "What will be the output of the following Python expression?" ,
"expression" : "print(4.00/(2.0+2.0))" ,
"correct": "1.0",
"options": [
" Error",
"1.00",
"1.0",
"1"
],
"Explanation" : "The result of the expression shown above is 1.0 because print rounds off digits."
},
{
"id":"52",
"category" : "Precedence and Associativity – 2",
"instruction" : "What will be the value of X in the following Python expression?" ,
"expression" : "X = 2+9*((3*12)-8)/10" ,
"correct": "27.2",
"options": [
" 30.8",
"30.0",
" 28.4",
"27.2"
],
"Explanation" : " The expression shown above is evaluated as: 2+9*(36-8)/10, which simplifies to give 2+9*(2.8), which is equal to 2+25.2 = 27.2. Hence the result of this expression is 27.2."
},
{
"id":"53",
"category" : "Precedence and Associativity – 2",
"instruction" : "Which of the following expressions involves coercion when evaluated in Python?" ,
"expression" : "" ,
"correct": "1.7 % 2",
"options": [
"1.7 % 2",
"4.7 – 1.5",
" 7.9 * 6.3",
" 3.4 + 4.6"
],
"Explanation" : " Coercion is the implicit (automatic) conversion of operands to a common type. Coercion is automatically performed on mixed-type expressions. The expression 1.7 % 2 is evaluated as 1.7 % 2.0 (that is, automatic conversion of int to float)."
},
{
"id":"54",
"category" : "Precedence and Associativity – 2",
"instruction" : "What will be the output of the following Python expression?" ,
"expression" : "24//6%3, 24//4//2" ,
"correct": "(1,3)",
"options": [
"(0,3)",
"(1,0)",
"(1,3)",
"(3,1)"
],
"Explanation" : "The expressions are evaluated as: 4%3 and 6//2 respectively. This results in the answer (1,3). This is because the associativity of both of the expressions shown above is left to right."
},
{
"id":"55",
"category" : "Precedence and Associativity – 2",
"instruction" : "Which among the following list of operators has the highest precedence?" ,
"expression" : "+, -, **, %, /, <<, >>, |" ,
"correct": "**",
"options": [
" <<, >>",
"**",
" |",
" %"
],
"Explanation" : "The highest precedence is that of the exponentiation operator, that is of **."
},
{
"id":"56",
"category" : "Precedence and Associativity – 2",
"instruction" : "What will be the value of the following Python expression?" ,
"expression" : "float(4+int(2.39)%2)" ,
"correct": "4.0",
"options": [
"5.0",
"4.0",
" 5",
" 4"
],
"Explanation" : "The above expression is an example of explicit conversion. It is evaluated as: float(4+int(2.39)%2) = float(4+2%2) = float(4+0) = 4.0. Hence the result of this expression is 4.0."
},
{
"id":"57",
"category" : "Precedence and Associativity – 2",
"instruction" : "Which of the following expressions is an example of type conversion?" ,
"expression" : "" ,
"correct": "4.0 + float(3)",
"options": [
"5.3 + 6.3",
"5.0 + 3",
"4.0 + float(3)",
"3 + 7"
],
"Explanation" : "Type conversion is nothing but explicit conversion of operands to a specific type. Options 5.3 + 6.3 and 5.0 + 3 are examples of implicit conversion whereas option 4.0 + float(3) is an example of explicit conversion or type conversion."
},
{
"id":"58",
"category" : "Precedence and Associativity – 2",
"instruction" : "Which of the following expressions results in an error?" ,
"expression" : "" ,
"correct": "int(’10.8’)",
"options": [
"float(‘10’)",
" int(‘10’)",
"float(’10.8’)",
"int(’10.8’)"
],
"Explanation" : "All of the above examples show explicit conversion. However the expression int(’10.8’) results in an error."
},
{
"id":"59",
"category" : "Precedence and Associativity – 2",
"instruction" : "What will be the value of the following Python expression?" ,
"expression" : "4+2**5//10" ,
"correct": "7",
"options": [
"3",
"7",
"77",
"0"
],
"Explanation" : " The order of precedence is: **, //, +. The expression 4+2**5//10 is evaluated as 4+32//10, which is equal to 4+3 = 7. Hence the result of the expression shown above is 7."
},
{
"id":"60",
"category" : "Precedence and Associativity – 2 TF",
"instruction" : "The expression 2**2**3 is evaluates as: (2**2)**3." ,
"expression" : "" ,
"correct": "False",
"options": [
"True",
"False"
],
"Explanation" : "The value of the expression (2**2)**3 = 4**3 = 64. When the expression 2**2**3 is evaluated in python, we get the result as 256, because this expression is evaluated as 2**(2**3). This is because the associativity of exponentiation operator (**) is from right to left and not from left to right."
},
{
"id":"61",
"category" : "Bitwise – 1",
"instruction" : "What will be the output of the following Python code snippet if x=1?" ,
"expression" : "x<<2" ,
"correct": "4",
"options": [
"8",
"4",
" 1",
" 2"
],
"Explanation" : "The binary form of 1 is 0001. The expression x<<2 implies we are performing bitwise left shift on x. This shift yields the value: 0100, which is the binary form of the number 4."
},
{
"id":"62",
"category" : "Bitwise – 1",
"instruction" : "What will be the output of the following Python expression?" ,
"expression" : "bin(29)" ,
"correct": "‘0b11101’",
"options": [
"‘0b10111’",
" ‘0b11111’",
"‘0b11101’",
"‘0b11011’"
],
"Explanation" : "The binary form of the number 29 is 11101. Hence the output of this expression is ‘0b11101’"
},
{
"id":"63",
"category" : "Bitwise – 1",
"instruction" : "What will be the value of x in the following Python expression, if the result of that expression is 2?" ,
"expression" : "x>>2" ,
"correct": "8",
"options": [
"8",
" 4",
"2",
" 1"
],
"Explanation" : " When the value of x is equal to 8 (1000), then x>>2 (bitwise right shift) yields the value 0010, which is equal to 2. Hence the value of x is 8."
},
{
"id":"64",
"category" : "Bitwise – 1",
"instruction" : "What will be the output of the following Python expression?" ,
"expression" : "int(1011)?" ,
"correct": "1011",
"options": [
" 11",
"13",
"1011",
"1101"
],