In a predict and run task you do not write code from scratch. You start from a small piece of working code, work out what you think it will do before you run it, and then run it to check whether you were right.
This task contains two examples, one for each of the new operators.
For every example, study the code carefully and write down a prediction of what
it will do when it runs. Your prediction should use the key terms variable,
operator and output, and it should name the operator the example is
about: modulo or exponentiation. Predict the exact numbers that are
output. You can type your prediction straight into the code as a comment, on a
line starting with #.
Only once you have written your prediction should you run the code and compare the result with what you expected.
Need more help with arithmetic operators? Click here.
total_sweets = 17
people = 5
left_over = total_sweets % people
print("Sweets left over: " + str(left_over))
Predict the number in the output. Then work out how many sweets each person
gets, and change people to 4 and predict again before you run it.
side_length = 4
base_area = side_length ** 2
total_volume = side_length ** 3
print("Base area is " + str(base_area))
print("Total volume is " + str(total_volume))
Predict both numbers. Then say what shape these two lines are measuring, and
what the output would be if the ** on both lines were a single *.
Make sure that you check for the following things:
= for assignment.** are written next to each other, with no space between
them.% gives the remainder, not a percentage.print is wrapped in str().