Input - Lakelands Computing

Title
Go to content
The Input () Function
The input () function is key if you want to allow users to interact with your program without you having to build a graphical user interface (using something like TKinter)

Input lets you ask the user a question and they type in their answer eg:

  • input("what is your name?")

You can also use it with the print statement eg:

  • print ("what is your name?")
  • input()

The only difference is where the cursor is to allow the user to type (run the trinket to see what I mean)

You can store the data from input using a variable (more on that here) eg:

  • name = input("what is your name?")

Data collected via input() defaut to being a string (text). So if you want it to be an Integer (whole number) you need to cast it (more on casting data types here). eg

  • age = int(input("how old are you?")

All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content