Running code, values, and output
Objective
Distinguish code, a value, printed output, and a returned answer.
Distinguish code, a value, printed output, and a returned answer.
Explanation
A program is a sequence of instructions. Python evaluates expressions such as 2 + 3 to produce values. Numbers are written without quotes; text needs quotes. print displays a value so a person can see it. It does not turn that display into the answer expected by an exercise.
The example runs from top to bottom. In early practice, a supplied function is a small wrapper around your work: replace only the expression after return. You do not need to design the wrapper yet. A comment starts with # and explains code without running. The assert lines are supplied checks: they stop with an error if the stated comparison is false. We will learn to write these checks later. Use Run code to compare your returned answer with the examples; a failed test is feedback, not a grade.
Worked example
print("Hello, learner!")
print(2 + 3)
assert 2 + 3 == 5
Common mistakes
Putting quotes around 2 + 3 prints the text rather than calculating. Printing inside the exercise wrapper without returning an answer produces None.
Guided practice
Predict the two printed lines, then change the greeting and add a calculation. In the supplied wrapper, return the number 7 instead of printing it.
Independent practice
Try the exercises linked below. Predict an answer before running code, and explain one boundary case in your own words.
Recap
Distinguish code, a value, printed output, and a returned answer. Compare the result with your prediction and use small examples to explain any difference.