10000 Merge pull request #2 from ihf-code/tweaks/lesson_5 · zfoxpython/intro-to-python@2d761a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d761a8

Browse files
authored
Merge pull request ihf-code#2 from ihf-code/tweaks/lesson_5
Tweaks/lesson 5
2 parents e0d8943 + b8f44cf commit 2d761a8

File tree

6 files changed

+51
-47
lines changed

6 files changed

+51
-47
lines changed

session_03/answers/A7.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# A7 - Your company has had a great year and are going to offer a bonus of 10% to any employee who has a service of over 3 years.
1+
# A7 - Your company has had a great year and are going to offer a bonus of 10% to any employee who has a service of over 3 years.
22
# Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one.
3-
# salary = int(input("What is your current salary?\n"))
4-
# years_of_service = int(input("How many years have you worked here?\n"))
3+
salary = int(input("What is your current salary?\n"))
4+
years_of_service = int(input("How many years have you worked here?\n"))
55

66
if years_of_service > 3:
77
print("Your current salary is" + str(salary)+ ", your bonus is" + str(salary*0.1))
88
else:
9-
print("Your current salary is" + str(salary)+ ", you get no bonus.")
9+
print("Your current salary is" + str(salary)+ ", you get no bonus.")

session_03/answers/B7.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# B7 - Take the age and name of three people and determine who is the oldest and youngest
2-
# and print out the name and age of the oldest and youngest.
1+
# B7 - Take the age and name of three people and determine who is the oldest and youngest
2+
# and print out the name and age of the oldest and youngest.
33
# If all three ages are the same, print that.
44

55
name1 = input("What is your name?\n")
@@ -9,22 +9,22 @@
99
name3 = input("What is your name?\n")
1010
age3 = int(input("How old are you?\n"))
1111

12-
#Oldest
12+
#Oldest
1313
if age1 > age2 and age1 > age3:
1414
print(name1 + "is the oldest and is " + str(age1) + "years old.")
1515
elif age2 > age1 and age2 > age3:
1616
print(name2 + "is the oldest and is " + str(age2) + "years old.")
17-
elif age3 > age1 and age3> age2:
17+
elif age3 > age1 and age3> age2:
1818
print(name3 + "is the oldest and is " + str(age3) + "years old.")
19-
else:
20-
("You are all the same age")
19+
else:
20+
print("You are all the same age")
2121

2222
#Youngest
2323
if age1 < age2 and age1 < age3:
2424
print(name1 + "is the youngest and is " + str(age1) + "years old.")
2525
elif age2 < age1 and age2 < age3:
2626
print(name2 + "is the youngest and is " + str(age2) + "years old.")
27-
elif age3 < age1 and age3 < age2:
27+
elif age3 < age1 and age3 < age2:
2828
print(name3 + "is the youngest and is " + str(age3) + "years old.")
29-
else:
30-
("You are all the same age")
29+
else:
30+
print("You are all the same age")

session_03/exercises/multiple_choice_3.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
1. What is a conditional?
44
- an expression that allows a user to enter an input
5-
- an expression that allows a computer to make a decision - A
5+
- an expression that allows a computer to make a decision - A
66
- an expression that allows a computer to print an output
77
- an expression that makes a string upper case
88

99
2. What will be the output of the below:
10-
sum = 5 + 6
10+
sum = 5 + 6
1111

1212
if sum == 10:
1313
print("The value is 10")
1414

1515
- 10
1616
- The value is 10
17-
- There will be no output - A
18-
- 11
17+
- There will be no output - A
18+
- 11
1919

2020
3. What will be the output of the below:
2121
name = "Jackie"
@@ -26,24 +26,24 @@ if name == "Anita":
2626

2727
print("Thanks")
2828

29-
- Thanks - A
29+
- Thanks - A
3030
- Hello Anita
3131
- How are you?
3232
- Hello Anita How are you? Thanks
3333

34-
4. What does the == comparator mean?
34+
4. What does the == comparator mean?
3535

3636
- equals - A
37-
- does not equal
37+
- does not equal
3838
- greater than
39-
- less than or equal to
39+
- less than or equal to
4040

41-
5. What does the != comparator mean?
41+
5. What does the != comparator mean?
4242

4343
- equals
4444
- does not equal - A
4545
- greater than
46-
- less than or equal to
46+
- less than or equal to
4747

4848
6. What is the output of below?
4949
age = 15
@@ -53,7 +53,7 @@ else:
5353
print("You cannot vote")
5454

5555
- You can vote
56-
- You cannot vote - A
56+
- You cannot vote - A
5757

5858
7. What is the output of below?
5959
traffic_light = "red"
@@ -69,7 +69,7 @@ else:
6969
- STOP!
7070
- You can go! - A
7171

72-
8. What will be the output of the below:
72+
8. What will be the output of the below:
7373
age = 0
7474

7575
if age <= 13:
@@ -81,23 +81,23 @@ elif age == 0:
8181
else:
8282
print("You are 19 or over")
8383

84-
- You are 13 or younger - A
84+
- You are 13 or younger - A
8585
- You are between 14 and 17
86-
- You aren't born yet
87-
- You are 19 or over
86+
- You aren't born yet
87+
- You are 19 or over
8888

89-
9. What will be the output of the below:
89+
9. What will be the output of the below:
9090
age = 14
9191
if age > 12 and age < 20:
9292
print("You are a teenager")
9393

94-
- You are a teenager
94+
- You are a teenager
9595
- You are not a teenager
9696

97-
10. What will be the output of the below:
97+
10. What will be the output of the below:
9898
age = 12
9999
if age < 13 or age > 19:
100100
print("You are not a teenager")
101101

102102
- You are a teenager
103-
- You are not a teenager
103+
- You are not a teenager - A

session_03/slides/session_3.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ z = str(10.0) # z will be '10.0'
8181

8282
# Index
8383

84-
| C | H | A | R | L | I | E |
85-
| --- | --- | --- | --- | --- | --- | --- |
86-
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
87-
| -7 | -6 | -5 | -4 | -3 | -2 | -1 |
84+
85+
| A | L | A | N | T | U | R | I | N | G |
86+
| --- | --- | --- | --- | --- | --- | --- | -- | -- | -- |
87+
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
88+
8889

8990

9091
```python
91-
name = "CHARLIE"
92-
print(name[0]) # Prints 'C' - first index item
93-
print(name[1]) # Prints 'H'
94-
print(name[-1]) # Prints 'E' - last index item
92+
fullname = "Alan" + "Turing"
93+
length = len(fullname) # 10
94+
# int(length / 2) = 5
95+
middle_letter = fullname[5].lower()
9596
```
9697

9798
---
@@ -318,7 +319,7 @@ if age <= 13:
318319
elif age < 18:
319320
print("You are between 14 and 17")
320321
elif age == 0:
321-
# This can never be run
322+
# This will never get run
322323
print("You aren't born yet")
323324
else:
324325
print("You are 19 or over")
@@ -365,4 +366,3 @@ if not (age > 12 and age < 20):
365366

366367
# [fit] Coding Time
367368
## Section B
368-

session_04/slides/session_4.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ if age <= 13:
116116
elif age < 18:
117117
print("You are between 14 and 17")
118118
elif age == 0:
119-
# This can never be run
119+
# This will never get run
120120
print("You aren't born yet")
121121
else:
122122
print("You are 19 or over")
@@ -324,4 +324,4 @@ range(2000, 2020, 4)
324324
---
325325

326326
# [fit] Coding Time
327-
## Section B
327+
## Section B

session_05/slides/session_5.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ for person in names:
7575

7676
```python
7777
# Create variables to store our numbers and counts
78-
numbers = [1, 10, 13 , 15, 765, 32, 65, 23, 56, 101]
78+
numbers = [1, 10, 13, 15, 765, 32, 65, 23, 56, 101]
7979
even_count = 0
8080
odd_count = 0
8181

@@ -85,8 +85,7 @@ for i in numbers:
8585
if i % 2 == 0:
8686
even_count = even_count + 1
8787
else:
88-
# This is short hand for the line above
89-
odd_count += 1
88+
odd_count = odd_count + 1
9089

9190
print("Even: " + str(even_count))
9291
print("Odd: " + str(odd_count))
@@ -450,4 +449,9 @@ for x in range(times_to_loop):
450449

451450
---
452451

452+
# [fit] Coding Time
453+
## Section A
454+
455+
---
456+
453457
### Questions?

0 commit comments

Comments
 (0)
0