|
1 | 1 | # KPMG:Code - Session 7 - Multiple Choice Questions
|
2 | 2 |
|
3 |
| -1. What is a dictionary in Python? |
| 3 | +1. What is a function in Python? |
4 | 4 | - a way to allow user input
|
5 | 5 | - a statement that allows a computer to make a decision
|
6 |
| -- a way to print an output |
7 |
| -- a collection of data - A |
| 6 | +- re-usable, self-contained blocks of code that do a single task - A |
| 7 | +- a collection of data |
| 8 | + |
| 9 | +2. What key word defines a function? |
| 10 | +- def - A |
| 11 | +- input |
| 12 | +- print |
| 13 | +- parameter |
| 14 | + |
| 15 | +3. How would I call the following function: |
| 16 | +def hello_world(): |
| 17 | + print("Hello World!") |
| 18 | + |
| 19 | +- hello_world |
| 20 | +- hello world () |
| 21 | +- hello_world() - A |
| 22 | +- hello world |
| 23 | + |
| 24 | +4. What does the principle of 'DRY' stand for? |
| 25 | +- do repeat yourself |
| 26 | +- don't repeat yourself - A |
| 27 | +- do return yourself |
| 28 | +- don't reload yourself |
| 29 | + |
| 30 | +5. What is name classed as here: |
| 31 | +def hello(name): |
| 32 | + print("Hello, " + name + "!") |
| 33 | + |
| 34 | +- function |
| 35 | +- string |
| 36 | +- parameter - A |
| 37 | +- class |
8 | 38 |
|
9 |
| -2. What brackets does a dictionary use? |
10 |
| -- {} - A |
11 |
| -- () |
12 |
| -- [] |
13 |
| -- <> |
| 39 | +6. What would be the ouput of the below: |
| 40 | +def hello(name): |
| 41 | + print("Good Morning, " + name) |
14 | 42 |
|
15 |
| -3. A dictionary is an unordered collection of data. |
16 |
| -- True - A |
17 |
| -- False |
| 43 | +hello("Grace") |
18 | 44 |
|
19 |
| -4. A tuple can be modified |
20 |
| -- True |
21 |
| -- False - A |
| 45 | +- Grace |
| 46 | +- Good Morning Grace Hopper |
| 47 | +- Good Morning Grace - A |
| 48 | +- good morning Grace |
22 | 49 |
|
23 |
| -5. What will be the output of the below: |
24 |
| -shirt = { |
25 |
| - "size": "Large", |
26 |
| - "colour": "Red" |
27 |
| -} |
| 50 | +7. What would be the ouput of the below: |
| 51 | +def volume(x, y, z): |
| 52 | + print("The volume is " + str(x * y * z)) |
28 | 53 |
|
29 |
| -print(shirt["size"]) |
| 54 | +volume(12, 4, 6) |
30 | 55 |
|
31 |
| -- size |
32 |
| -- colour |
33 |
| -- Large |
34 |
| -- Red |
| 56 | +- 228 |
| 57 | +- 288 - A |
| 58 | +- 114 |
| 59 | +- 144 |
35 | 60 |
|
36 |
| -6. What would be the ouput of the below: |
37 |
| -contacts = [ |
38 |
| - {"fname": "Ada", "lname": "Lovelace"}, |
39 |
| - {"fname": "Alan", "lname": "Turing", "phone": "555-1234"}, |
40 |
| - {"fname": "Steve", "lname": "Shirley"} |
41 |
| -] |
42 |
| - |
43 |
| -for person in contacts: |
44 |
| - if "phone" in person: |
45 |
| - print(person["fname"]) |
46 |
| - |
47 |
| -- Ada |
48 |
| -- Alan |
49 |
| -- Steve - A |
50 |
| -- 555-1234 |
51 |
| - |
52 |
| -7. What will stop this while loop: |
53 |
| -contacts = [] |
54 |
| -fname = None |
55 |
| - |
56 |
| -while fname != "": |
57 |
| - fname = input("What is your first name? ") |
58 |
| - lname = input("What is your last name? ") |
59 |
| - |
60 |
| - if fname and lname: |
61 |
| - contacts.append({ |
62 |
| - "fname": fname, |
63 |
| - "lname": lname |
64 |
| - }) |
65 |
| - |
66 |
| -- nothing, it will run forever |
67 |
| -- entering a first name |
68 |
| -- not entering a first name |
69 |
| -- not entering a first name and last name |
70 |
| - |
71 |
| -8. Items in a dictionary are called _____ pairs. |
72 |
| - |
73 |
| -- key, value - A |
74 |
| -- value, key |
75 |
| -- key, arguments |
76 |
| -- value, arguments |
77 |
| - |
78 |
| -9. What will be the output of the below: |
79 |
| -shirt = { |
80 |
| - "size": "Large", |
81 |
| - "colour": "Red" |
82 |
| -} |
83 |
| - |
84 |
| -shirt["colour"] = "Green" |
85 |
| - |
86 |
| -- adds a new key/value |
87 |
| -- changes an existing value - A |
88 |
| -- deletes the key/value pair |
89 |
| -- prints out the dictionary |
| 61 | +8. What is returning, in relation to functions? |
| 62 | + |
| 63 | +- return is a keyword - A |
| 64 | +- return is a function |
| 65 | +- return is a input |
| 66 | +- return is a parameter |
| 67 | + |
| 68 | +9. Which of the below will stop the execution a function? |
| 69 | + |
| 70 | +- print |
| 71 | +- return - A |
90 | 72 |
|
91 | 73 | 10. What will be the output of the below:
|
92 |
| -shirt = { |
93 |
| - "size": "Large", |
94 |
| - "colour": "Red" |
95 |
| -} |
| 74 | +def calc_factorial(x): |
| 75 | + if x == 1: |
| 76 | + return 1 |
| 77 | + else: |
| 78 | + return (x * calc_factorial(x - 1)) |
| 79 | + |
| 80 | +num = 4 |
96 | 81 |
|
97 |
| -del(shirt["size"]) |
| 82 | +print(calc_factorial(num)) |
98 | 83 |
|
99 |
| -- adds a new key/value |
100 |
| -- changes an existing value |
101 |
| -- deletes the key/value pair - A |
102 |
| -- prints out the dictionary |
| 84 | +- 4 |
| 85 | +- None |
| 86 | +- 24 - A |
| 87 | +- 6 |
0 commit comments