Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Which of these four programs shows something? Say it before you run each one.
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, go through the solution one step at a time, and check each step against your own.
Plan. A function runs only when it is called, and a call needs the brackets.
hello and calls it with hello(). It shows Hello once.hello without brackets. This only names the function. It does not call it, so nothing is shown.hello and never calls it. Nothing is shown.Hello twice.Check. Run the four programs one at a time, and count the lines of output: 1, 0, 0 and 2.
Answer: Programs 1 and 4 show something (once and twice). Programs 2 and 3 show nothing.
Log in to join the discussion.
Loading…