User Input

Python has an input function which allows a user enters an input. You call this function to tell the program to stop and wait for the user to key in the data. The program will resume once the user presses the ENTER or RETURN key.

In [2]: name = input("What is your name: ")

Above we have created a variable to request the name of our user. Lets see what the output would be.

In [2]: name = input("What is your name: ")
print("Did you say your name is?", name)

Out[2]: What is your name:

Now the program is waiting for the user’s input. We have added an output to ask the user if the name they provided was okay.

In [2]: name = input ("What is your name: ")
print ("Did you say your name is?", name)

Out[2]: What is your name:
Did you say your name is? Mannie Young

Above we can see that the user gave an input Mannie Young which was stored and asked if the name was correct.

Lets try and asked for the user’s favorite number.

In [2]: favNum = input ("Whats's your favorite number: ")
print ("\n Your favorite number is: ", favNum)

Out[2]: What's your favorite number:
Your favorite number is: 7

Above we can see that the input was 7. We would notice that for the first time we have a line break between the question and the output, this was made possible by the \n which means new line.

results matching ""

    No results matching ""