User Input - Python

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Getting User Input

We can use the input() command to get user typed input into our program. This is different from the print statement because we need to use the input statement to store the input. So:

name = input("Enter your name")

In this example name is just a variable, this can be used to store what ever the user has typed. You can then do something with the value, for example write it to the screen:

name = input("Enter your name")
print("hello " + name)

When you run the program you should get a popup input screen, or alternatively it will write the text within the input command and then provide you with a command line cursor to write your value. You will need to press enter after your input.

Now Try

Create a program to generate movie plots, input:

  • Famous (the name of a famous person)
  • Situation (where they find themselves)
  • Goal (what they have to do to get out of it)

Then write:

  • (Famous) as found themselves in a tricky situation, (Situation). The only way out is for them to (Goal). Will they make it???