|
1 | | -# [fit] IHF: Code |
| 1 | +# [fit] KPMG: Code |
2 | 2 | ## [fit] Python — Session 6 — Lesson |
3 | | -### Live at 10am |
4 | 3 |
|
5 | 4 | --- |
6 | 5 |
|
7 | 6 | # Review |
8 | 7 |
|
9 | 8 | --- |
10 | 9 |
|
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 | | - |
132 | 10 | # Modules |
133 | 11 |
|
134 | 12 | ```python |
@@ -267,7 +145,6 @@ for x in range(times_to_loop): |
267 | 145 | --- |
268 | 146 |
|
269 | 147 | ## Any Questions? |
270 | | -### sli.do #ihfcode |
271 | 148 |
|
272 | 149 | --- |
273 | 150 |
|
@@ -504,14 +381,3 @@ while fname != "": |
504 | 381 |
|
505 | 382 | # [fit] Coding Time |
506 | 383 | ## 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 |
0 commit comments