If you want to take inputs from the console in your Python program then you can make use of the built-in function called input()
Let's see an example where the user is prompted to enter his name and a greeting message is displayed back.
# Code2care PROGRAM Programming:
# This program demonstrates
# how you can collect input
# from the console using the
# built in input() function
# in python.
print("Hello there! Please Enter your name:")
name = input()
print('Hello! {0}, How are you doing today?'.format(name))
Program Output:
Hello there! Please Enter your name: Chris
Hello! Chris, How are you doing today?
Process finished with exit code 0
As you can see after the first print message the console waits for the user to input something in the console, once the user press enters the program move ahead and the inputted string is stored in the variable.

What if the program needs two inputs from the user?
This is easy, all you will do is make use of the input() function twice in your code wherever it is required, let's see an example where you want to add two numbers inputted by the user,
# Code2care PROGRAM Programming:
# Add two numbers using two numbers inputted by
# user in the console
print('This Program Adds Two Numbers inputted by the user in console:')
print('Enter 1st Number:')
number1 = int(input())
print('Enter 2nd Number:')
number2 = int(input())
sumOfNumbers = number1 + number2
print('Sum: {0} + {1} = {2}'.format(number1, number2, sumOfNumbers))
Note that we have typecasted the input string as an int in order to treat it as an integer.
Have Questions? Post them here!
- Check version of pip package installer for Python
- How to install Python 3.9 using brew on Mac
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- Indent Python code in Notepad++
- Change label (text) color in tkinter
- Float built-in function in Python
- [Fix] ValueError: substring not found in Python
- pip get list of all outdated Python packages
- Calculate discount amount python code
- 3 Python program to add two numbers
- How to List all Packages installed using pip [Python]
- Python range() function examples
- How to resolve Failed to create interpreter PyCharm Error
- Format Python Code in Visual Studio Code (VS Code)
- Validate email address in Python using regular expression (regex)
- Install and Run Jupyter Notebook on Mac (macOS)
- How to delete a file using Python code example
- Base64 Encoding Decoding in Python Programming
- How to pip install Python Modules in VSCode
- Change the background of Tkinter label or text
- Comments in Python Programming
- Take input argument from command line in Python Programming
- How to Convert Python String to DateTime Object
- Tkinter - add x and y padding to label text
- [Tutorial] Install Python on Visual Studio Code (VS Code)
- [Fix] Cannot connect to Microsoft SQL Server, Error: 18456 - Microsoft
- How to know list of images available on your device - Docker
- What is Carbon Lang (successor to C++?) experimental Language by Google - News
- How to Change Text Size for Android ActionBar - Android
- Git Commit - Author identity unknown, Please tell me who you are email - Git
- macOS Big Sur compatible Macs List - MacOS
- Programmatically check if Facebook is installed on Android device - Android
- Telegram down in Europe - users facing connection issues and 500 Internal Server error - News