Input

Read through this page carefully. At the bottom is a link to the simulation.

Run-time input

We can give a variable a value with an assignment statement like

a = 4

but often we want the value to be chosen by the user, not the programmer.

We can do this by having something like

input a

in the program. Then when this runs, the user can choose a value for the variable.

This makes the program much more flexible - we do not have to re-write it to use different values. But we do need to make sure it will work properly whatever the user types in.

How do we choose what to input?

When we run the program, we are pretending to be the user, rather than the programmer. We can type in any value, the same as a user could.

You might choose input values to test whether th eprogram works correctly. This means you must work out what output should be produced, and compare it with the actual output.

Input in the simulator

A statement like

input a

reads in a value from the input box. this means something must be entered into the input box before the statement is executed.

If the program needs several input values, they should be separted by commas

Next - simulation step 2