8000 Updated session 7 slides and answers · gelmok/intro-to-python@71bce07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71bce07

Browse files
committed
Updated session 7 slides and answers
1 parent 8469c7b commit 71bce07

File tree

15 files changed

+109
-33
lines changed

15 files changed

+109
-33
lines changed

session_07/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
In this session we cover:
44
- What are functions and why we use them
55
- Creating your own functions
6-
- DRY Principle
6+
- DRY principle
77
- Calling functions
88
- Parameters
9-
- Returning values from Functions
9+
- Returning values from functions
1010
- Recursion

session_07/answers/A1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# A1 - Write a function that prints your name
22

3-
43
def print_name():
54
print("My name")
65

session_07/answers/A2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# A2 - Write a function that accepts a name as a parameter and prints "Hello, "
22

3-
43
def hello(name):
54
print("Hello, " + name + "!")
65

session_07/answers/A3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# A3 - Loop through the list ["Alice", "Bob", "Charlie"] and call the function you just wrote
2+
23
def hello(name):
34
print("Hello, " + name + "!")
45

session_07/answers/A4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# A4 - Write a function that prints the area of two passed in parameters
2+
23
def area(w, h):
34
print("The area is " + str(w * h))
45

session_07/answers/A5.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# A5 - Write a function called 'print_list' that accepts a list as a parameter and then prints out each item of the list
2+
23
def print_list(fruits):
34
for fruit in fruits:
45
print(fruit)

session_07/answers/A6.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# iii. If they are over 16, print 'You're too old for school"
55
# vi. If they are 0, print "You're not born yet!"
66

7-
87
def school_eligibility(age):
98
if age < 11:
109
print("You're too young to go to this school.")

session_07/answers/B1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# B1 - Write a function called is_odd that will return True if the integer is odd and
22
# False if the integer passed as a parameter is even (hint: x % 2 will return true for all odd numbers)
33

4-
54
def is_odd(number):
65
if number % 2 == 1:
76
return True

session_07/answers/B2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# B2 - Write a function that accepts a word and returns it backwards, e.g. 'hello' -> 'olleh'
22

3-
43
def reverse_word(name):
54
#METHOD 1
65
new_string = ""

session_07/answers/B3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# **
66
# *
77

8-
98
def print_stars(x):
109
star = ""
1110
for y in range(0, x):

0 commit comments

Comments
 (0)
0