Skip to content

Commit 12b4d63

Browse files
authored
Create unit7_ex7.2.1.py
1 parent 603ffaf commit 12b4d63

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

unit7_ex7.2.1.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# exercise 7.2.1 from unit 7
2+
'''
3+
Write a function called is_greater defined as follows:
4+
5+
def is_greater(my_list, n):
6+
The function accepts two parameters: a list and a number n.
7+
The function returns a new list containing all the elements that are greater than the number n.
8+
9+
An example of running the is_greater function:
10+
>>> result = is_greater([1, 30, 25, 60, 27, 28], 28)
11+
>>> print(result)
12+
[30, 60]
13+
'''
14+
15+
def is_greater(my_list, n):
16+
result = []
17+
for element in my_list:
18+
if element > n:
19+
result.append(element)
20+
return result
21+
22+
def main():
23+
result = is_greater([1, 30, 25, 60, 27, 28], 28)
24+
print(result) # print [30, 60]
25+
result = is_greater([1, 2, 3, 4, 5, 6], 3)
26+
print(result) # print [4, 5, 6]
27+
result = is_greater([10, 20, 30, 40], 15)
28+
print(result) # print [20, 30, 40]
29+
result = is_greater([1, 2, 3, 4, 5, 6], 6)
30+
print(result) # print []
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)