Skip to content

Commit af66e41

Browse files
authored
Merge pull request #103 from lironmiz/unit7-Ex7.2.4.py
Create unit7_ex7.2.4.py
2 parents 020c57e + a1fffbf commit af66e41

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

unit7_ex7.2.4.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# exercise 7.2.4 from unit 7
2+
'''
3+
Write a function called seven_boom which simulates the game "Seven Boom". The function is defined as:
4+
5+
def seven_boom(end_number):
6+
The function accepts an integer, end_number.
7+
The function returns a list in the range of numbers 0 to end_number inclusive, with certain numbers replaced by the string 'BOOM', if they meet one of the following conditions:
8+
9+
The number is a multiple of the number 7.
10+
The number contains the digit 7.
11+
Example of running the seven_boom function:
12+
>>> print(seven_boom(17))
13+
['BOOM', 1, 2, 3, 4, 5, 6, 'BOOM', 8, 9, 10, 11, 12, 13, 'BOOM', 15, 16, 'BOOM']
14+
'''
15+
16+
def seven_boom(end_number):
17+
result = []
18+
for i in range(1, end_number+1):
19+
if i % 7 == 0 or '7' in str(i):
20+
result.append('BOOM')
21+
else:
22+
result.append(i)
23+
return result
24+
25+
def main():
26+
print(seven_boom(21))
27+
28+
if __name__ == '__main__':
29+
main()

0 commit comments

Comments
 (0)