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!
- Read JSON File in Python Program
- Convert Float to String in Python
- Python - Convert float to String
- Check if String Contains a Substring - Python
- Install and Run Jupyter Notebook on Mac (macOS)
- Sorting an array using Bubble Sort in Python Programming
- Comments in Python Programming
- 3 Python program to add two numbers
- Read a file line by line in Python Program
- How to uninstall pip Python packages
- Change label (text) color in tkinter
- 7 Python Arithmetic Operators with Examples [Tutorial]
- pip get list of all outdated Python packages
- Where does brew install python in macOS
- How to Convert String to DateTime in Python
- Python: Fix command not found pip or pip3 on zsh shell
- How to add borders to tkinter label text
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- TypeError: must be str, not int
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- Check version of pip package installer for Python
- Change the background of Tkinter label or text
- Set width and height for the label in tkinter
- How to write JSON file in Python Program
- Python raise error with message example
- 12 August - International Youth Day celebrated worldwide - News
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console - Java
- airbnb website and mobile App is down worldwide - clear browser cache or reinstall app to fix error - News
- Mac (macos) startup keyboard boot sequence combinations - MacOS
- Test internet speed using macOS Terminal command - MacOS
- zsh: command not found [fix] macOS - zsh
- How to install Postman natively on a Mac - HowTos
- Add blank lines after each lines using Notepad++ text editor - NotepadPlusPlus