CMU Coding Bootcamp
1def howManyPizzas(students: int, slicesPerStudent: int) -> int:
2 """Check how many pizzas are needed given that each pizza has 8 slices."""
3 neededSlices = students * slicesPerStudent
4 return (neededSlices + 7) // 8
5
6
7def leftoverPizzaSlices(students: int, slicesPerStudent: int) -> int:
8 """Check how many slices of pizza will be leftover given that each pizza has 8 slices."""
9 neededSlices = students * slicesPerStudent
10 totalSlices = howManyPizzas(students, slicesPerStudent) * 8
11 return totalSlices - neededSlices
12
13
14print("Testing howManyPizzas()...", end="")
15assert howManyPizzas(8, 1) == 1
16assert howManyPizzas(9, 1) == 2
17assert howManyPizzas(5, 4) == 3
18assert howManyPizzas(10, 2) == 3
19assert howManyPizzas(0, 0) == 0
20assert howManyPizzas(0, 3) == 0
21assert howManyPizzas(10, 0) == 0
22assert howManyPizzas(3, 4) == 2
23print("Passed!")
24
25print("Testing leftoverPizzaSlices()...", end="")
26assert leftoverPizzaSlices(8, 1) == 0
27assert leftoverPizzaSlices(9, 1) == 7
28assert leftoverPizzaSlices(5, 4) == 4
29assert leftoverPizzaSlices(10, 2) == 4
30assert leftoverPizzaSlices(0, 0) == 0
31assert leftoverPizzaSlices(0, 3) == 0
32assert leftoverPizzaSlices(10, 0) == 0
33assert leftoverPizzaSlices(3, 4) == 4
34print("Passed!")