loading
So far in this tutorial series, we have created simple programs that do not require any user input. However today we will begin to learn about input statements which take a user input from what the person running the program types. As always please favourite, comment and subscribe

Step 1: The Code

After opening a blank python file type the following code:

userName = input('What is your name ')
print('Hello', userName)


How this works is that on the first line the computer is creating a variable called userName, what happens next is the variable userName gets filled with whatever is typed by the user at that point. The computer will wait until the enter key is pressed before continuing Which allows strings of multiple characters to be entered.

----WARNING----

Whatever you type into an input statement it will always be an string. To create an integer you would type:

userAge = int(input('How old are you? '))

Or:

userAge = input('How old are you? ')
userAgeInt = int(userAge)

We will go over the use of int() later in the series

The syntax for an input statement is:
variableName = input('optional prompt')

You may have noticed in the first example how we put a few spaces at the end of the prompt, this is because otherwise it would force you to begin typing your input right up next to the last word of the prompt and as well how i say the prompt is optional because if you just type input() it will still request an input but it won't have the prompt there to tell you what to type.
I love this tutorial, I was doing cousera python course, and I got stuck for hours on the input function, 10 min with this tutorial and I totally understood what I was doing wrong.<br>Thank you :-)
I love hearing things like this! although I stopped the python tutorials, I am thinking of creating a new series on modding games or a different language entirely
<p>I guess I don't know enough about python to understand this....</p>

About This Instructable

342views

10favorites

License:

Bio: 1 new python tutorial every day Comment what you want the next one to be Please favourite and subscribe Notice Board: - since instructables has automatically ... More »
More by BlueBlood Studios:Teach Me Python #7: Control Statements Pt.2: While Loops Teach My Python #6: Control Statements Pt.1: If, Else And Elif Teach Me Python #5: Simple Maths 
Add instructable to: