Skip to content

Commit a610e2b

Browse files
readme update + some exercises from 5.1
1 parent ebbe05a commit a610e2b

File tree

4 files changed

+72
-35
lines changed

4 files changed

+72
-35
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
5. [Print statement formatting](https://github.com/antoniolopez7217/Python_Programming_MOOC/tree/main/part4/5.%20Print%20statement%20formatting)
2828
6. [More strings and lists](https://github.com/antoniolopez7217/Python_Programming_MOOC/tree/main/part4/6.%20More%20strings%20and%20lists)
2929

30-
### [Part 5]()
30+
### [Part 5](https://github.com/antoniolopez7217/Python_Programming_MOOC/tree/main/part5)
3131
1. [More lists]()
3232
2. [References]()
3333
3. [Dictionary]()

part3/README.md

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# Part 3
22
## Programming exercises
33
### Loops with conditions
4-
1. [Print numbers](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/print_numbers.py)
5-
2. [Fix the code: Countdown](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/countdown.py)
6-
3. [Numbers](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/numbers.py)
7-
4. [Powers of two](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/powers_two.py)
8-
5. [Powers of base n](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/power_basen.py)
9-
6. [The sum of consecutive numbers, version 1](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/sum_consec_numb_v1.py)
10-
7. [The sum of consecutive numbers, version 2](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/sum_consec_numb_v2.py)
4+
1. [Print numbers](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/print_numbers.py)
5+
2. [Fix the code: Countdown](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/countdown.py)
6+
3. [Numbers](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/numbers.py)
7+
4. [Powers of two](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/powers_two.py)
8+
5. [Powers of base n](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/power_basen.py)
9+
6. [The sum of consecutive numbers, version 1](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/sum_consec_numb_v1.py)
10+
7. [The sum of consecutive numbers, version 2](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/1.%20Loops%20with%20conditions/sum_consec_numb_v2.py)
1111
### Working with strings
12-
1. [String multiplied](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/string_multiplied.py)
13-
2. [The longer string](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/longer_string.py)
14-
3. [End to beginning](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/end_beginning.py)
15-
4. [Second and second to last characters](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/second_last_chars.py)
16-
5. [A line of hashes](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/line_hashes.py)
17-
6. [A rectangle of hashes](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/rectangle_hashes.py)
18-
7. [Underlining](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/underlining.py)
19-
8. [Right-aligned](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/right_aligned.py)
20-
9. [A framed word](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/framed_word.py)
21-
10. [Substrings, part 1](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/substrings_p1.py)
22-
11. [Substrings, part 2](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/substrings_p2.py)
23-
12. [Does it contain vowels](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/contain_vowels.py)
24-
13. [Find the first substring](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/first_substring.py)
25-
14. [Find all the substrings](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/find_all_substring.py)
26-
15. [The second occurrence](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/second_ocurrence.py)
12+
1. [String multiplied](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/string_multiplied.py)
13+
2. [The longer string](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/longer_string.py)
14+
3. [End to beginning](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/end_beginning.py)
15+
4. [Second and second to last characters](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/second_last_chars.py)
16+
5. [A line of hashes](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/line_hashes.py)
17+
6. [A rectangle of hashes](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/rectangle_hashes.py)
18+
7. [Underlining](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/underlining.py)
19+
8. [Right-aligned](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/right_aligned.py)
20+
9. [A framed word](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/framed_word.py)
21+
10. [Substrings, part 1](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/substrings_p1.py)
22+
11. [Substrings, part 2](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/substrings_p2.py)
23+
12. [Does it contain vowels](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/contain_vowels.py)
24+
13. [Find the first substring](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/first_substring.py)
25+
14. [Find all the substrings](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/find_all_substring.py)
26+
15. [The second occurrence](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/2.%20Working%20with%20strings/second_ocurrence.py)
2727
### More loops
28-
1. [Multiplication](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/multiplication.py)
29-
2. [First letters of words](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/first_letter_word.py)
30-
3. [Factorial](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/factorial.py)
31-
4. [Flip the pairs](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/flip_pairs.py)
32-
5. [Taking turns](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/taking_turns.py)
28+
1. [Multiplication](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/3.%20More%20loops/multiplication.py)
29+
2. [First letters of words](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/3.%20More%20loops/first_letter_word.py)
30+
3. [Factorial](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/3.%20More%20loops/factorial.py)
31+
4. [Flip the pairs](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/3.%20More%20loops/flip_pairs.py)
32+
5. [Taking turns](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/3.%20More%20loops/taking_turns.py)
3333
### Defining functions
34-
1. [Seven Brothers](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/seven_brothers.py)
35-
2. [The first character](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/first_character.py)
36-
3. [Mean](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/mean.py)
37-
4. [Print many times](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/print_many_times.py)
38-
5. [A square of hashes](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/square_hashes.py)
39-
6. [Chessboard](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/chessboard.py)
40-
7. [A word squared](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/word_squared.py)
34+
1. [Seven Brothers](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/seven_brothers.py)
35+
2. [The first character](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/first_character.py)
36+
3. [Mean](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/mean.py)
37+
4. [Print many times](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/print_many_times.py)
38+
5. [A square of hashes](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/square_hashes.py)
39+
6. [Chessboard](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/chessboard.py)
40+
7. [A word squared](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part3/4.%20Defining%20functions/word_squared.py)
4141

4242
*All subjects are included as comments within the file of each exercise.*

part5/1. More lists/longest_string.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Please write a function named longest(strings: list), which takes a list of strings as its argument.
2+
# The function finds and returns the longest string in the list.
3+
# You may assume there is always a single longest string in the list.
4+
5+
# An example of expected behaviour:
6+
7+
8+
# if __name__ == "__main__":
9+
# strings = ["hi", "hiya", "hello", "howdydoody", "hi there"]
10+
# print(longest(strings))
11+
12+
# howdydoody
13+
14+
def longest(strings: list):
15+
long = strings[0]
16+
for item in strings:
17+
if len(item) > len(long):
18+
long = item
19+
return long
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Please write a function named count_matching_elements(my_matrix: list, element: int),
2+
# which takes a two-dimensional array of integers and a single integer value as its arguments.
3+
# The function then counts how many elements within the matrix match the argument value.
4+
#
5+
# An example of how the function should work:
6+
#
7+
# m = [[1, 2, 1], [0, 3, 4], [1, 0, 0]]
8+
# print(count_matching_elements(m, 1))
9+
#
10+
# 3
11+
12+
def count_matching_elements(my_matrix: list, element: int):
13+
counter = 0
14+
for row in my_matrix:
15+
for item in row:
16+
if item == element:
17+
counter += 1
18+
return counter

0 commit comments

Comments
 (0)