Simple coding
Simple coding

Start this free course now. Just create an account and sign in. Enrol and complete the course for a free statement of participation or digital badge if available.

Free course

Simple coding

5.1 The input function

Another very useful function is input: it takes a string that it prints on the screen (the user’s prompt), and returns a string with what the user typed on the keyboard until they pressed the RETURN or ENTER key. Run the code below and type in your name, followed by RETURN or ENTER.

Note that input always returns a string, even if the user typed in a number. To see the implications of that, run the code below and type in your birth year.

The computer reports a type error, because the code is mixing two different types of data. It is trying to subtract the string returned by input from the number 2015.


Take your learning further

Making the decision to study can be a big step, which is why you'll want a trusted University. The Open University has 50 years’ experience delivering flexible learning and 170,000 students are studying with us right now. Take a look at all Open University courses.

If you are new to university level study, find out more about the types of qualifications we offer, including our entry level Access courses and Certificates.

Not ready for University study then browse over 900 free courses on OpenLearn and sign up to our newsletter to hear about new free courses as they are released.

Every year, thousands of students decide to study with The Open University. With over 120 qualifications, we’ve got the right course for you.

Request an Open University prospectus