Simple Arithmetic, Input and Output in Python

Reading User Input

Similar to the outputting text to the terminal using the print() function, it is possible reading input into our programs by using the input()function.

name = input ("Please enter your name : ")
print ("Hi", name)

The code given above will prompt the user Please enter your name : and wait for an input. When the user pressed the enter key after inputting some text, the program assigns the input text to the name variable, and uses that value in the print() function on the next line. You should either use the command line terminal or the terminal inside the PyCharm to feed the input.

Functions returning values can be direct arguments to other functions, as in:

print ("Welcome", input("Please enter your name : "))

where the Python interpreter will first execute the input ("Please enter your name : ") inside the second print function and use the return value of that input() function call as an argument to invoke the print() function itself.

name = input ("Please enter your name : ")
print ("Hi", name)

print ("Welcome", name, input("Please enter your last name : "))

You can experiment with the source code using the following example: