Skip to content

Commit 0a4f61f

Browse files
part 5.4 added + some exercises
1 parent 45f8f17 commit 0a4f61f

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

part5/4. Tuple/create_tuple.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Please write a function named create_tuple(x: int, y: int, z: int),
2+
# which takes three integers as its arguments, and creates and returns a tuple based on the following criteria:
3+
4+
# The first element in the tuple is the smallest of the arguments
5+
# The second element in the tuple is the greatest of the arguments
6+
# The third element in the tuple is the sum of the arguments
7+
# An example of its use:
8+
9+
10+
# if __name__ == "__main__":
11+
# print(create_tuple(5, 3, -1))
12+
13+
# (-1, 5, 7)
14+
15+
def create_tuple(x: int, y: int, z: int):
16+
values = [x, y, z]
17+
return (min(values), max(values), sum(values))

part5/4. Tuple/oldest_person.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Please write a function named oldest_person(people: list), which takes a list of tuples as its argument.
2+
# In each tuple, the first element is the name of a person, and the second element is their year of birth.
3+
# The function should find the oldest person on the list and return their name.
4+
5+
# An example of the function in action:
6+
7+
# p1 = ("Adam", 1977)
8+
# p2 = ("Ellen", 1985)
9+
# p3 = ("Mary", 1953)
10+
# p4 = ("Ernest", 1997)
11+
# people = [p1, p2, p3, p4]
12+
13+
# print(oldest_person(people))
14+
15+
# Mary
16+
17+
def oldest_person(people: list):
18+
oldest = people[0][0]
19+
year = people[0][1]
20+
for person in people:
21+
if person[1] < year:
22+
year = person[1]
23+
oldest = person[0]
24+
return oldest
25+

part5/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
8. [Movie database](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part5/3.%20Dictionary/movie_database.py)
2727
9. [Find movies](https://github.com/antoniolopez7217/Python_Programming_MOOC/blob/main/part5/3.%20Dictionary/find_movies.py)
2828
### Tuple
29-
1. Create a tuple
30-
2. The oldest person
31-
3. Older people
32-
4. Student database
33-
5. A square of letters
29+
1. [Create a tuple]()
30+
2. [The oldest person]()
31+
3. [Older people]()
32+
4. [Student database]()
33+
5. [A square of letters]()
3434

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

0 commit comments

Comments
 (0)