8000 Updated session 6 slides/answers and multiple choice questions · zfoxpython/intro-to-python@8469c7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8469c7b

Browse files
committed
Updated session 6 slides/answers and multiple choice questions
1 parent d410a78 commit 8469c7b

File tree

7 files changed

+108
-149
lines changed

7 files changed

+108
-149
lines changed

session_06/answers/A2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"Colour": "Green"
77
}
88

9-
apple["Best Before Date"] = "08/10/2019"
9+
apple["Best Before Date"] = "08/10/2023"
1010
print(apple)

session_06/answers/B2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Create a menu with 5 items.
1+
# A3 - Create a menu with 5 items.
22
# Store this information in a dictionary inside a list.
33
# Each item in the menu should have the name of the item, the price and if its vegetarian friendly (make at least one vege friendly dish).
44
# Print out the entire menu.

session_06/examples/.gitignore

Whitespace-only changes.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# KPMG:Code - Session 6 - Multiple Choice Questions
2+
3+
1. What is a dictionary in Python?
4+
- a way to allow user input
5+
- a statement that allows a computer to make a decision
6+
- a way to print an output
7+
- a collection of data - A
8+
9+
2. What brackets does a dictionary use?
10+
- {} - A
11+
- ()
12+
- []
13+
- <>
14+
15+
3. A dictionary is an unordered collection of data.
16+
- True - A
17+
- False
18+
19+
4. A tuple can be modified
20+
- True
21+
- False - A
22+
23+
5. What will be the output of the below:
24+
shirt = {
25+
"size": "Large",
26+
"colour": "Red"
27+
}
28+
29+
print(shirt["size"])
30+
31+
- size
32+
- colour
33+
- Large
34+
- Red
35+
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
90+
91+
10. What will be the output of the below:
92+
shirt = {
93+
"size": "Large",
94+
"colour": "Red"
95+
}
96+
97+
del(shirt["size"])
98+
99+
- adds a new key/value
100+
- changes an existing value
101+
- deletes the key/value pair - A
102+
- prints out the dictionary

session_06/slides/answers_6.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
# [fit] IHF: Code
1+
# [fit] KPMG: Code
22
## [fit] Python — Session 6 — Answers
3-
### Live at 10am
43

54
---
65

76
## Any Questions
8-
9-
### go to sli.do #python2020
10-
11-
---
12-
13-
# [fit] Next Session
14-
### Tuesday 19th May 10am
15-
### Lesson 7

session_06/slides/session_6.md

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,12 @@
1-
# [fit] IHF: Code
1+
# [fit] KPMG: Code
22
## [fit] Python — Session 6 — Lesson
3-
### Live at 10am
43

54
---
65

76
# Review
87

98
---
109

11-
# List
12-
```python
13-
days = ["Mon", "Tue", "Wed", "Thurs", "Fri", "Sat", "Sun"]
14-
15-
print(days)
16-
# ["Mon", "Tue", "Wed", "Thurs", "Fri", "Sat", "Sun"]
17-
18-
print(days[1]) # Tue
19-
```
20-
---
21-
22-
# List
23-
24-
```python
25-
names = ["Alice", "Bob", "Charlie"]
26-
27-
names.append("Dave") # ["Alice", "Bob", "Charlie", "Dave"]
28-
29-
names[2] = "Chris" # ["Alice", "Bob", "Chris", "Dave"]
30-
31-
del(names[1])# ["Alice", "Chris", "Dave"]
32-
33-
if "Eve" in names:
34-
print("Eve is here")
35-
36-
for name in names:
37-
print(name)
38-
```
39-
40-
---
41-
42-
# For Loops
43-
44-
```python
45-
names = ["Alice", "Bob", "Charlie"]
46-
47-
for person in names:
48-
print(person)
49-
50-
# Alice
51-
# Bob
52-
# Charlie
53-
```
54-
55-
---
56-
57-
# For Loops
58-
59-
```python
60-
# Create variables to store our numbers and counts
61-
numbers = [1, 10, 13 , 15, 765, 32, 65, 23, 56, 101]
62-
even_count = 0
63-
odd_count = 0
64-
65-
# Loop through all our numbers
66-
for i in numbers:
67-
# Check to see if the number is odd/even
68-
if i % 2 == 0:
69-
even_count = even_count + 1
70-
else:
71-
# This is short hand for the line above
72-
odd_count += 1
73-
74-
print("Even: " + str(even_count))
75-
print("Odd: " + str(odd_count))
76-
```
77-
78-
---
79-
80-
# For Loops
81-
82-
```python
83-
for letter in "supercalifragilisticexpialidocious":
84-
print(letter.upper())
85-
```
86-
87-
---
88-
89-
# Ranges
90-
91-
[.code-highlight: 1-2]
92-
[.code-highlight: 4-5]
93-
[.code-highlight: 7-8]
94-
```python
95-
range(10)
96-
#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
97-
98-
range(1, 5)
99-
#[1, 2, 3, 4]
100-
101-
range(2000, 2020, 4)
102-
#[2000, 2004, 2008, 2012, 2016]
103-
```
104-
105-
---
106-
107-
# For Loops
108-
109-
```python
110-
for olympic_years in range(1896, 2020, 4):
111-
print(olympic_years)
112-
113-
# ...
114-
# 2008
115-
# 2012
116-
# 2016
117-
```
118-
119-
---
120-
121-
# For Loops
122-
123-
```python
124-
times_to_ask = int(input("How many times should I ask? "))
125-
126-
for x in range(times_to_ask):
127-
print(input("What is your name? "))
128-
```
129-
130-
---
131-
13210
# Modules
13311

13412
```python
@@ -267,7 +145,6 @@ for x in range(times_to_loop):
267145
---
268146

269147
## Any Questions?
270-
### sli.do #ihfcode
271148

272149
---
273150

@@ -504,14 +381,3 @@ while fname != "":
504381

505382
# [fit] Coding Time
506383
## Section B
507-
508-
---
509-
510-
### Questions?
511-
### go to sli.do #ihfcode
512-
513-
---
514-
515-
# [fit] Next Session
516-
### Thursday 14th May 2pm
517-
### Answers

session_06/slides/thumbnails_6.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# [fit] IHF: Code
1+
# [fit] KPMG: Code
22
## [fit] Python — Session 6 — Lesson
33

44
---
55

6-
# [fit] IHF: Code
6+
# [fit] KPMG: Code
77
## [fit] Python — Session 6 — Answers

0 commit comments

Comments
 (0)
0