Lesson goal: Getting input from the keyboard

Previous: Random numbers | Home | Next: Getting clicks from the mouse

Having a computer program interact with the person using it is extremely important. By this we mean having a program take some action in direct response to something you may type into it. For the programming lessons here, we'll use the keyboard as our primary interaction device. In other words, we'll learn here how to read input from the keyboard, then use that input in your programs.

To read text from the keyboard, we'll use a pre-defined function called input(). It works like this:

Move the mouse over a dotted box for more information.

Now you try. Try using input() to read something from the keyboard, and into a variable.

Type your code here:

See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.