Tuesday 2 October 2012

Python Input

Inputting information into the computer

Running programs is ok but they do the same thing each time. In some ways this is good, but to be really useful the computer needs input.

Let us consider the ways of entering information

counter = 1

This sets counter to hold a value


The input statement allows us to enter different information each time the program is run.

age = input (" What is your age?")

We start with a variable in this case age and after the input statement we ask a question.
What is your age?
The program looks and runs better if we put a space after the question mark and before the quote

When we type in an age now the text looks better presented.

Once the number is added then hit the enter or return key and this number is put into the age variable as the program is running.

When we ask the program to print out the answer - the value of age - then what ever you typed in is what ois displayed.
Now to get you to do some work.

Write me a program do do any times table you wish
Get the program to ask you which times table 
The get the program to ask you how many
Then use a loop and a sum to display it.

An answer is at the top of this blog.

No comments:

Post a Comment