Sunday, June 5, 2011

Storing things

Let's look at this:
The first line puts a number in age. I didn't find that word somewhere, or know from memory, I just made it up. If you make up a word and tell the computer it equals something, then the computer thinks it is what you put it equal to. This is called a variable. The code above is the same as:
Try typing each of them in below and seeing if it's different when you click the Run button. Variables can be set to words too:
Now try this:
When you click the Run button, the computer asks you for your age. When you type it in, then the age variable contains whatever you typed in. It doesn't have to be your age, you could type "happy", "young enough", or "none of my business". We can do math here as well:
The int() function makes age into a number instead of words.

Try the examples out below:

No comments:

Post a Comment