-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedin_test_IV.py
928 lines (597 loc) · 22.7 KB
/
linkedin_test_IV.py
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
########## DECLARE VARIABLES ##########
totalQuestions = 36
correctAnswers = 0
incorrectAnswers = []
########## Q109 ##########
number = '109'
correct = 'D'
question = input(
number + ". What will be the value of x after running this code?\n"
" x = {1,2,3,4,5}\n"
" x.add(5)\n"
" x.add(6)\n\n"
"A. {1, 2, 3, 4, 5, 5, 6}\n"
"B. {5, 6, 1, 2, 3, 4, 5, 6}\n"
"C. {6, 1, 2, 3, 4, 5}\n"
"D. {1, 2, 3, 4, 5, 6}\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q110 ##########
number = '110'
correct = 'D'
question = input(
number + ". How would you access and store all of the keys in this dictionary at once?\n"
" fruit_info = {\n"
" 'fruit': 'apple',\n"
" 'count': 2,\n"
" 'price': 3.5\n"
" }\n\n"
"A. my_keys = fruit_info.to_keys()\n"
"B. my_keys = fruit_info.all_keys()\n"
"C. my_keys = fruit_info.keys\n"
"D. my_keys = fruit_info.keys()\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q111 ##########
number = '111'
correct = 'C'
question = input(
number + ". What is wrong with this function definition?\n"
" def be_friendly(greet = 'How are you!', name):\n"
" pass\n\n"
"A. name is a reserved word.\n"
"B. Underscores are not allowed in function names.\n"
"C. A non-default argument follows a default argument.\n"
"D. There is nothing wrong with this function definition.\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q112 ##########
number = '112'
correct = 'A'
question = input(
number + ". Given that NumPy is imported as np, which choice will return True?\n\n"
"A. \n"
"a = np.zeros([3,4])\n"
"b = a.copy()\n"
"np.array_equal(a,b)\n"
"B. \n"
"a = np.empty([3,4])\n"
"b = np.empty([3,4])\n"
"np.array_equal(a,b)\n"
"C. \n"
"a = np.zeros([3,4])\n"
"b = np.zeros([4,3])\n"
"np.array_equal(a,b)\n"
"D. \n"
"a = np.array([1, np.nan])\n"
"np.array_equal(a,a)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q113 ##########
number = '113'
correct = 'B'
question = input(
number + ". How do you add a comment to existing Python script?\n\n"
"A. // This is a comment\n"
"B. # This is a comment\n"
"C. -- This is a comment\n"
"D. /* This is a comment *\\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q114 ##########
number = '114'
correct = 'D'
question = input(
number + ". In this code fragment, what will the values of c and d be equivalent to?\n"
" import numpy as np\n"
" a = np.array([1,2,3])\n"
" b = np.array([4,5,6])\n"
" c = a*b\n"
" d = np.dot(a,b)\n\n"
"A. \n"
"c = [ a[1] * b[1], a[2] * b[2], a[3] * b[3] ]\n"
"d = sum(c)\n"
"B. \n"
"c = a[0] * b[0], a[1] * b[1], a[2] * b[2]\n"
"\n"
"d = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]\n"
"C. \n"
"c = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]\n"
"\n"
"d = sum(a) + sum(b)\n"
"D. \n"
"c = [ a[0] * b[0], a[1] * b[1], a[2] * b[2] ]\n"
"\n"
"d = sum(c)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q115 ##########
number = '115'
correct = 'A'
question = input(
number + ". What two functions within the NumPy library could you use to solve a system of linear equations?\n\n"
"A. linalg.eig() and .matmul()\n"
"B. linalg.inv() and .dot()\n"
"C. linalg.det() and .dot()\n"
"D. linalg.inv() and .eye()\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q116 ##########
number = '116'
correct = 'B'
question = input(
number + ". What is the correct syntax for creating a variable that is bound to a list?\n\n"
"A. my_list = (2, 'apple', 3.5)\n"
"B. my_list = [2, 'apple', 3.5]\n"
"C. my_list = [2, 'apple', 3.5].to_list()\n"
"D. my_list = to_list(2, 'apple', 3.5)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q117 ##########
number = '117'
correct = 'D'
question = input(
number + ". This code provides the _ of the list of numbers.\n"
" num_list = [21, 13, 19, 3, 11, 5, 18]\n"
" num_list.sort()\n"
" num_list[len(num_list) // 2]\n\n"
"A. mode\n"
"B. average\n"
"C. mean\n"
"D. median\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q118 ##########
number = '118'
correct = 'D'
question = input(
number + ". What are the two main data structures in the Pandas library?\n\n"
"A. Arrays and DataFrames\n"
"B. Series and Matrixes\n"
"C. Matrixes and DataFrames\n"
"D. Series and DataFrames\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q119 ##########
number = '119'
correct = 'D'
question = input(
number + ". Suppose you have a variale named vector of type np.array with 10,000 elements. How can you turn vector into a variable named matrix with dimensions 100x100?\n\n"
"A. matrix = (vector.shape = (100,100))\n"
"B. matrix = vector.to_matrix(100,100)\n"
"C. matrix = matrix(vector,100,100)\n"
"D. matrix = vector.reshape(100, 100)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q120 ##########
number = '120'
correct = 'D'
question = input(
number + ". Which choice is an immutable data type?\n\n"
"A. dictionnary\n"
"B. list\n"
"C. set\n"
"D. string\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q121 ##########
number = '121'
correct = 'C'
question = input(
number + ". What is the output of this code?\n"
" def myFunction(country = 'France'):\n"
" print('Hello, I am from', country)\n"
"\n"
" myFunction('Spain')\n"
" myFunction("")\n"
" myFunction()\n\n"
"A. \n"
"Hello, I am from Spain\n"
"Hello, I am from\n"
"Hello, I am from\n"
"B. \n"
"Hello, I am from France\n"
"Hello, I am from France\n"
"Hello, I am from France\n"
"C. \n"
"Hello, I am from Spain\n"
"Hello, I am from\n"
"Hello, I am from France\n"
"D. \n"
"Hello, I am from Spain\n"
"Hello, I am from France\n"
"Hello, I am from France\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q122 ##########
number = '122'
correct = 'D'
question = input(
number + ". Choose the option below for which instance of the class cannot be created\n\n"
"A. Anonymous Class\n"
"B. Parent Class\n"
"C. Nested Class\n"
"D. Abstract Class\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q123 ##########
number = '123'
correct = 'A'
question = input(
number + ". Using Pandas, we load a data set from Kaggle, as structured in the image below. Which command will return the total number of survivors?\n\n"
"A. sum(titanic['Survived'])\n"
"B. [x for x in titanic['Survived'] if x == 1]\n"
"C. len(titanic[''Survived''])\n"
"D. sum(titanic['Survived']==0)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q124 ##########
number = '124'
correct = 'B'
question = input(
number + ". How would you create a list of tuples matching these lists of characters and actors?\n"
" characters = ['Iron Man', 'Spider Man', 'Captain America']\n"
" actors = ['Downey', 'Holland', 'Evans']\n\n"
"A. \n"
"[(x,y)] for x in characters for y in actors]\n"
"B. \n"
"zip(characters, actors)\n"
"C. \n"
"d = {}\n"
"\n"
"for x in range(1, len(characters)):\n"
" d[x] = actors[x]\n"
"D. \n"
"{x:y for x in characters for y in actors}\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q125 ##########
number = '125'
correct = 'B'
question = input(
number + ". What will this statement return?\n"
" {x : x*x for x in range(1,100)}\n\n"
"A. a dictionary with x as a key, and x squared as its value; from 1 to 100\n"
"B. a dictionary with x as a key, and x squared as its value; from 1 to 99\n"
"C. a set of tuples, consisting of (x, x squared); from 1 to 99\n"
"D. a list with all numbers squared from 1 to 99\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q126 ##########
number = '126'
correct = 'B'
question = input(
number + ". Jaccard Similarity is a formula that tells you how similar two sets are. It is defined as the cardinality of the intersection divided by the cardinality of the union. Which choice is an accurate implementation in Python?\n\n"
"A. def jaccard(a, b): return len (a | b) / len (a & b)\n"
"B. def jaccard(a, b): return len (a & b) / len (a | b)\n"
"C. def jaccard(a, b): return len (a && b) / len (a || b)\n"
"D. def jaccard(a, b): return a.intersection(b) / a.union(b)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q127 ##########
number = '127'
correct = 'D'
question = input(
number + ". Which choice is not a native numerical type in Python?\n\n"
"A. Long\n"
"B. Int\n"
"C. Float\n"
"D. Double\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q128 ##########
number = '128'
correct = 'B'
question = input(
number + ". What will be the output of this code?\n"
" [1,2,3] * 3\n\n"
"A. [3,2,3]\n"
"B. [1, 2, 3, 1, 2, 3, 1, 2, 3]\n"
"C. You will get a type error.\n"
"D. [3,6,9]\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q129 ##########
number = '129'
correct = 'B'
question = input(
number + ". Given a list defined as numbers = [1,2,3,4], what is the value of numbers[-2]?\n\n"
"A. 1\n"
"B. 2\n"
"C. 3\n"
"D. An IndexError exception is thrown.\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q130 ##########
number = '130'
correct = 'A'
question = input(
number + ". Which statement about strings in Python is true?\n\n"
"A. Strings can be enclosed by double quotes ('') or single quotes (').\n"
"B. Strings can only be enclosed in single quotes (').\n"
"C. Single character strings must be enclosed in single quotes ('), and the rest must be enclosed in double quotes ('').\n"
"D. Strings can only be enclosed in double quotes ('').\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q131 ##########
number = '131'
correct = 'D'
question = input(
number + ". What is the correct syntax for defining an init() method that takes no parameters?\n\n"
"A. definit(self): pass\n"
"B. classinit(self): pass\n"
"C. classinit(): pass\n"
"D. definit(): pass\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q132 ##########
number = '132'
correct = 'C'
question = input(
number + ". Suppose you need to use the sin function from the math library. What is the correct syntax for importing only that function?\n\n"
"A. using math.sin\n"
"B. import math.sin\n"
"C. from math import sin\n"
"D. import sin from math\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q133 ##########
number = '133'
correct = 'B'
question = input(
number + ". What do you get if you apply numpy.sum() to a list that contains only Boolean values?\n\n"
"A. 0\n"
"B. the count of all True values\n"
"C. a type error\n"
"D. None\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q134 ##########
number = '134'
correct = 'B'
question = input(
number + ". What will this code print?\n"
" print ('foo' if (256).bit_length() > 8 else 'bar')\n\n"
"A. True\n"
"B. foo\n"
"C. You will get an error message because constant integer values are not classes.\n"
"D. bar\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q135 ##########
number = '135'
correct = 'D'
question = input(
number + ". If you do not explicitly return a value from a function, what happens?\n\n"
"A. If the return keyword is absent, the function will return True.\n"
"B. The function will enter an infinite loop because it will not know when to stop executing its code.\n"
"C. The function will return a RuntimeError if you do not return a value.\n"
"D. If the return keyword is absent the function will return None.\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q136 ##########
number = '136'
correct = 'A'
question = input(
number + ". it is often the case that the pandas library is used for _ data and NumPy for _ data.\n\n"
"A. string; numerical\n"
"B. unstructured; structured\n"
"C. numerical; tabular\n"
"D. tabular; numerical\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q137 ##########
number = '137'
correct = 'B'
question = input(
number + ". What do you need to do to install additional packages into Python?\n\n"
"A. Use a C compiler like gcc or clang.\n"
"B. Use a package manager like pip or conda.\n"
"C. Use an IDE like Notepad++ or Idle.\n"
"D. Use a package manager like NPM or NuGet.\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q138 ##########
number = '138'
correct = 'B'
question = input(
number + ". The image below was created using Matplotlib. It is a distribution plot of a list of integers filled with numbers using the function _ and plotted with _.\n\n"
"A. random.uniform(0,50);plt.hist\n"
"B. random.gauss(50,20);plt.hist\n"
"C. random();plt.scatter\n"
"D. random.triangular(0,50);plt.bar\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q139 ##########
number = '139'
correct = 'A'
question = input(
number + ". In this code fragment, what will be the values of a and b?\n"
" import numpy as np\n"
" \n"
" a = np.arange(100)\n"
" b = a[50:60:2]\n\n"
"A. a: all integers from 0 to 99 (inclusive) b: all even integers from 50 to 58 (inclusive)\n"
"B. a: all integers from 0 to 100 (inclusive) b: all even integers from 50 to 60 (inclusive)\n"
"C. a: all integers from 0 to 99 (inclusive) b: all even integers from 50 to 60 (inclusive)\n"
"D. a: all integers from 0 to 99 (inclusive) b: all odd integers from 49 to 59 (inclusive)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q140 ##########
number = '140'
correct = 'B'
question = input(
number + ". When using NumPy in Python, how do you check the dimensionality (number and length of dimensions) of an object called my_object?\n\n"
"A. my_object.get_shape()\n"
"B. my_object.shape\n"
"C. my_object.dim()\n"
"D. len(my_object)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q141 ##########
number = '141'
correct = 'A'
question = input(
number + ". Assume you have a non-empty list named mylist and you want to search for a specific value. The minimum number of comparison will be __ and the maximum number of comparison will be _?\n\n"
"A. len(mylist); len(mylist)\n"
"B. 1; len(mylist)\n"
"C. 2; len(mylist)\n"
"D. 0; len(mylist)\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q142 ##########
number = '142'
correct = 'C'
question = input(
number + ". If a function does not have a return statement, what does it really return?\n\n"
"A. 0\n"
"B. True\n"
"C. None\n"
"D. False\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q143 ##########
number = '143'
correct = 'A'
question = input(
number + ". What is a common use of python's sys library?\n\n"
"A. to capture command-line arguments given at a file's runtime\n"
"B. to take a snapshot of all the packages and libraries in your virtual environment\n"
"C. to connect various systems, such as connecting a web front end, an API service, a database, and a mobile app\n"
"D. to scan the health of your Python ecosystem while inside a virtual environment\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## Q144 ##########
number = '144'
correct = 'D'
question = input(
number + ". Suppose you want to double-check if two matrices can be multipled using NumPy for debugging purposes. How would you complete this code fragment by filling in the blanks with the appropiate variables?\n"
" def can_matrices_be_multiplied (matrix1, matrix2):\n"
" rowsMat1, columnsMat1 = matrix1.shape\n"
" rowsMat2, columnsMat2 = matrix2.shape\n"
"\n"
" if _____ == ______ :\n"
" print('The matrices can be multipled!')\n"
" return True\n"
" else:\n"
" return False\n\n"
"A. columnsMat1; rowsMat1;\n"
"B. columnsMat1; rowsMat2;\n"
"C. columnsMat1; columnsMat2;\n"
"D. columnsMat2; rowsMat1;\n\n"
)
if (question == correct.upper() or question == correct.lower()):
correctAnswers = correctAnswers + 1
else:
incorrectAnswers.append(f"Question {number} (entered '{question}', correct '{correct}'),")
########## PRINT RESULTS ##########
print("Total Questions: " + str(totalQuestions))
print("Correct Answers: " + str(correctAnswers))
print("Final Grade: " + str((100 / totalQuestions) * correctAnswers) + "%")
for i in range(len(incorrectAnswers)):
print("\n" + incorrectAnswers[i])