Inputting Strings

Inputting a String

Remember that a string is a collection of alphanumeric characters (letters, numbers and punctuation) such as: “Wednesday”, “The Avengers 2: Age of Ultron”, “Boeing 747”. You must include speech marks when writing a string.

We use the input command to ask a question and let a user input data. After input you write your question in brackets and speech marks – like when printing. The user’s answer must be saved into a variable (e.g. name) which is written first.

Screenshot 2016-08-30 at 9.29.40 AM

You can then use that variable for all sorts, such as printing it within a sentence:

Screenshot 2016-08-30 at 9.41.02 AM

And when we run this program (F5) it will look like this:

Screenshot 2016-08-30 at 9.49.12 AM

The variable name can be whatever you want, just choose something appropriate:

Screenshot 2016-08-30 at 9.43.39 AM

 Screenshot 2016-08-30 at 9.44.30 AM

Practice Task 1

Inputting not working? Tick off these common errors:

Variable name written correctly?
Correct input line?
Used int for a whole number?
Have you used a comma between different sections?

< Back to Section Two