Skip to content

Commit f275e42

Browse files
committed
initial complete for intro activities
1 parent 2cb973d commit f275e42

22 files changed

+98
-50
lines changed

010_comments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
# yourself if you like.
8585

8686
# Type your name as a comment on the next line.
87+
# Nathan
8788

8889
# Hint: if you're on a Mac, type opt + 3 to get a #
8990

013_add_two.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
# YOUR FUNCTION GOES BELOW THIS LINE
1919

20-
20+
def add_two(num):
21+
return num + 2
2122

2223
# YOUR FUNCTION GOES ABOVE THIS LINE
2324

015_add_numbers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
# YOUR FUNCTION GOES BELOW THIS LINE
1414

15-
15+
def add_numbers(num1, num2):
16+
return num1 + num2
1617

1718
# YOUR FUNCTION GOES ABOVE THIS LINE
1819

016_operators.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,34 @@ def add_one(num):
5454

5555
# == Subtraction ==
5656

57-
# subtracted = 2 ? 3
58-
# print(f"2 ? 3 = {subtracted} (should be -1)")
57+
subtracted = 2 - 3
58+
print(f"2 - 3 = {subtracted} (should be -1)")
5959

6060
# == Division ==
6161

62-
# divided = 2 ? 3
63-
# print(f"2 ? 3 = {divided} (should be 0.6666666666666666)")
62+
divided = 2 / 3
63+
print(f"2 / 3 = {divided} (should be 0.6666666666666666)")
6464

6565
# This kind of 'decimal point' number, 0.6666666666666666 is
6666
# called a float, by the way, meaning 'floating point'.
6767

6868
# == Modulus ==
6969
# Sometimes known as "remainder if we divide 3 by 2"
7070

71-
# modulus = 3 ? 2
72-
# print(f"3 ? 2 = {modulus} (should be 1)")
71+
modulus = 3 % 2
72+
print(f"3 % 2 = {modulus} (should be 1)")
7373

7474
# == Floor division ==
7575
# Sometimes known as "division without remainder"
7676

77-
# floor_divided = 2 ? 3
78-
# print(f"2 ? 3 = {floor_divided} (should be 0)")
77+
floor_divided = 2 // 3
78+
print(f"2 // 3 = {floor_divided} (should be 0)")
7979

8080
# == Exponentiation ==
8181
# Sometimes known as "2 to the power of 3"
8282

83-
# expr = 2 ? 3
84-
# print(f"2 ? 3 = {expr} (should be 8)")
83+
expr = 2 ** 3
84+
print(f"2 ** 3 = {expr} (should be 8)")
8585

8686
# There are many more operators in Python that you can
8787
# research. You're very welcome to try out a few below:

021_two_step.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def add_one_and_divide_by_two_with_an_expression(num):
3939

4040
def divide_by_two_and_add_one(num):
4141
# Divide num by two and add one to the result
42-
pass # <-- This does nothing, replace it with your code
42+
return num / 2 + 1 # <-- This does nothing, replace it with your code
4343

4444
check_that_these_are_equal(
4545
divide_by_two_and_add_one(6),
@@ -53,7 +53,7 @@ def divide_by_two_and_add_one(num):
5353

5454
def multiply_by_forty_and_add_sixty(num):
5555
# Multiply num by forty, and then add sixty
56-
pass # <-- This does nothing, replace it with your code
56+
return num * 40 + 60 # <-- This does nothing, replace it with your code
5757

5858
check_that_these_are_equal(
5959
multiply_by_forty_and_add_sixty(3423),
@@ -67,7 +67,7 @@ def multiply_by_forty_and_add_sixty(num):
6767

6868
def add_together_and_double(num_a, num_b):
6969
# Add together num_a and num_b, then double the result
70-
pass # <-- This does nothing, replace it with your code
70+
return (num_a + num_b) * 2 # <-- This does nothing, replace it with your code
7171

7272
check_that_these_are_equal(
7373
add_together_and_double(3, 4),

022_strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Try out creating a string with your name in it:
2323

24-
your_name = ???
24+
your_name = "Nathan"
2525
print(your_name)
2626

2727
# @TASK: Check your work by running this file with:

023_string_indexing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
def get_first_letter(the_str):
5454
# Return the first letter of the string
55-
pass
55+
return the_str[0]
5656

5757
check_that_these_are_equal(
5858
get_first_letter("The king granted them"),
@@ -71,7 +71,7 @@ def get_first_letter(the_str):
7171

7272
def get_last_letter(the_str):
7373
# Return the last letter of the string
74-
pass
74+
return the_str[-1]
7575

7676
check_that_these_are_equal(
7777
get_last_letter("The king granted them"),
@@ -90,7 +90,7 @@ def get_last_letter(the_str):
9090

9191
def get_nth_letter(the_str, n):
9292
# Return the letter of the string at the specified index
93-
pass
93+
return the_str[n]
9494

9595
check_that_these_are_equal(
9696
get_nth_letter("The king granted them", 4),
@@ -110,7 +110,7 @@ def get_nth_letter(the_str, n):
110110
def get_letters_between_four_and_eight(the_str):
111111
# Return the section of the string between indexes four
112112
# and eight
113-
pass
113+
return the_str[4:8]
114114

115115
check_that_these_are_equal(
116116
get_letters_between_four_and_eight("The king granted them"),

024_string_operations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
new_string = old_string.replace("YOUR_NAME", "Kay")
4343

4444
# Uncomment this next line to see the result
45-
# print(new_string)
45+
print(new_string)
4646

4747
# You'll notice here that the function is coming in a
4848
# different place. Let's compare `len` and `replace`:
@@ -80,7 +80,7 @@
8080

8181
def make_uppercase(string):
8282
# Return the string in uppercase
83-
pass
83+
return string.upper()
8484

8585
check_that_these_are_equal(
8686
make_uppercase("hello"), "HELLO")
@@ -97,7 +97,7 @@ def make_uppercase(string):
9797

9898
def make_lowercase(string):
9999
# Return the string in lowercase
100-
pass
100+
return string.lower()
101101

102102
check_that_these_are_equal(
103103
make_lowercase("HELLO"), "hello")
@@ -115,7 +115,7 @@ def make_lowercase(string):
115115
def strip_whitespace(string):
116116
# Return the string with any whitespace removed from
117117
# the start and end
118-
pass
118+
return string.strip()
119119

120120
check_that_these_are_equal(
121121
strip_whitespace("hello "), "hello")

025_string_concatenation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
def greet(name):
5959
# Return the string "Hello, Kay!" where "Kay" is the
6060
# name provided
61-
pass
61+
return f"Hello, {name}!"
6262

6363
check_that_these_are_equal(
6464
greet("Chuang-tzu"),

026_ifs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
def is_first_of_the_month(day_number):
5555
# Return "First of the month!" if the day number is 1.
5656
# Return "Not first of the month" otherwise.
57-
pass
57+
if day_number == 1:
58+
return "First of the month!"
59+
else:
60+
return "Not first of the month"
5861

5962
check_that_these_are_equal(
6063
is_first_of_the_month(1),
@@ -75,7 +78,10 @@ def has_five_chars(the_str):
7578
# Return "STRING is five characters long" if the string
7679
# is five characters long.
7780
# Otherwise, return "Not five characters".
78-
pass
81+
if (len(the_str) == 5):
82+
return f"{the_str} is five characters long"
83+
else:
84+
return "Not five characters"
7985

8086
check_that_these_are_equal(
8187
has_five_chars("ABCDE"),

0 commit comments

Comments
 (0)