Skip to content

Commit 03efd18

Browse files
authored
Create unit5_ex5.3.7.py
1 parent cbd67c5 commit 03efd18

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: unit5_ex5.3.7.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# exercise 5.3.7 from unit 5
2+
'''
3+
We would like to connect chocolate cubes to a row that is x cm long. We have small
4+
chocolate cubes 1 cm long and large chocolate cubes 5 cm long.
5+
6+
For the purpose of the task, write a function called chocolate_maker defined as follows:
7+
8+
def chocolate_maker(small, big, x):
9+
The function receives the number of small cubes (small), the number of large cubes (big)
10+
and the desired line length (x). The function returns true if it is possible to create
11+
a line of length x using the number of chocolate cubes it received, all or some.
12+
13+
Guidelines
14+
Do not use loops.
15+
16+
Running examples of the chocolate_maker function
17+
>>> chocolate_maker(3, 1, 8)
18+
True
19+
>>> chocolate_maker(3, 1, 9)
20+
False
21+
>>> chocolate_maker(3, 2, 10)
22+
True
23+
'''
24+
25+
def chocolate_maker(small, big, x):
26+
one_total = small * 1
27+
five_total = big * 5
28+
if one_total + five_total == x or five_total == x or one_total == x:
29+
return True
30+
elif x - one_total > 0:
31+
if (x - one_total) % 5 == 0:
32+
return x <= five_total
33+
else:
34+
return False
35+
else:
36+
return True

0 commit comments

Comments
 (0)