Rounding and rolling
Answers are for parents and teachers.
1
What does this program print? import math, then print(math.ceil(3.01)) and print(math.floor(3.99)).
Python
1import math 2print(math.ceil(3.01)) 3print(math.floor(3.99))
4, then 3. ceil rounds 3.01 up to 4 and floor rounds 3.99 down to 3.
2
A baker packs 7 rolls in each bag. She has 30 rolls. Write the line that stores the number of full bags, and the line for the number of bags needed if every roll must be packed.
full = math.floor(30 / 7) gives 4. Needed = math.ceil(30 / 7) gives 5, because the last bag holds the 2 left over.
3
List the possible values of random.randint(4, 8) and say how many there are.
4, 5, 6, 7 and 8. That is 5 values, because both ends are included.
4
A program prints 10 * random.randint(2, 5). Can it print 25? Can it print 40? Explain.
It cannot print 25, because the results are 20, 30, 40 or 50 only. It can print 40 when randint gives 4.
5
Explain in two sentences why a programmer should give credit when using someone’s idea.
The idea belongs to the person who made it, so using it without credit would be dishonest. A comment saying who it came from shows respect and helps other people understand the code.