Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
One function shows its answer with print. Another returns it. What do the two programs show? Why can only the second answer be used in a sum?
print shows. return gives back. A function with no return gives back None.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
show_double(4) shows 8, and gives back nothing. So answer1 is None, and print(answer1) shows None.return_double(4) shows nothing by itself. It gives back 8, which is stored in answer2. print(answer2) shows 8.return_double(4) + 1 is 8 + 1, which shows 9.Answer: the program shows 8, None, 8 and 9.
Only a returned value can be used in a sum. A value that was only shown on the screen is gone.
Log in to join the discussion.
Loading…