8000 Added multiple choice for session 7 and updated content · zfoxpython/intro-to-python@0d32564 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d32564

Browse files
committed
Added multiple choice for session 7 and updated content
1 parent 71bce07 commit 0d32564

File tree

2 files changed

+82
-87
lines changed

2 files changed

+82
-87
lines changed
Lines changed: 72 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,87 @@
11
# KPMG:Code - Session 7 - Multiple Choice Questions
22

3-
1. What is a dictionary in Python?
3+
1. What is a function in Python?
44
- a way to allow user input
55
- 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
838

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)
1442

15-
3. A dictionary is an unordered collection of data.
16-
- True - A
17-
- False
43+
hello("Grace")
1844

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
2249

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))
2853

29-
print(shirt["size"])
54+
volume(12, 4, 6)
3055

31-
- size
32-
- colour
33-
- Large
34-
- Red
56+
- 228
57+
- 288 - A
58+
- 114
59+
- 144
3560

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
9072

9173
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
9681

97-
del(shirt["size"])
82+
print(calc_factorial(num))
9883

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

session_07/slides/session_7.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ def <function_name>(<param_1>, <param_2>, ...):
389389

390390
---
391391

392+
# Functions — Print vs Return
393+
394+
- print is a function you call. Use print when you want to show a value to a human.
395+
396+
- return is a keyword. When a return statement is reached, Python will stop the execution of the current function, sending a value out to where the function was called. Use return when you want to send a value from one point in your code to another.
397+
398+
- Using return changes the flow of the program. Using print does not.
399+
400+
---
401+
392402
# Functions — Returning
393403

394404
```python

0 commit comments

Comments
 (0)
0