How to run Python program in CMD
How to run python program in cmd
Command Prompt provides us all together with a different approach for dealing with our programs. The programs can be executed by accessing the directories.
In this article, we will discuss how we can run python programs in command prompt and what are the various commands we can use that can become a driving force towards our professional growth.
We have already discussed the steps of running a program in Python in previous articles.
Let’s have a quick recall
Running a program in command prompt-
Command Prompt acts as an interpreter in Windows and on specifying the correct path and by using the necessary commands, we can perform the required tasks. Typing 'cmd' in the search area of the taskbar will show the command prompt option and then we can start working on it.
- Open Command Prompt from the taskbar and run your file by specifying the file name.
- Make sure you provide the correct destination of your file.
We will execute the following program-
a=int(input("Enter 1st number: ")) #obtaining first value b=int(input("Enter 2nd number: ")) #obtaining second value c=a+b #performing addition print("Sum of a and b is {}".format(c)) #displaying the result
What exactly we need to do here is we will open a text editor in a system like Notepad and then write this program and save this file with an extension .py
Let us how it can be implemented-
- Open Notepad in your system and type the following program-

- Click on File and then click on ‘Save As’. Save your file with the extension .py

- Open the command prompt and make sure you correctly specify the destination of your file and then type the name of your file to access it.

- On clicking 'Enter' it will display the output and will ask the user to input the values for the addition of numbers.
- Once the values are provided, it will produce the desired output.
Commands that make you savvy with command prompt-
In this section, we will discuss the various commands that will help us to develop deeper insights into how to use the command prompt.
So, let's have a glance at the list of commands and their usage-
The commands in Windows Command Prompt are divided into four categories-
- Basics
- Files
- System
- Network
Commands that come under the ‘Basic’ category are-
- cls- This command clears the screen.
- cmd- This command starts the command prompt on our system.
- cd- This command changes the directory.
- exit- This command exits the command prompt or file.
- time- This command displays and helps us to edit the time of the system.
- ver- This command helps us to check the version of our operating system.
- echo- This command texts the output on the screen.
- date- This command shows and sets the date.
- dir- This command lists the contents of a directory.
- sort- This command sorts the output on the screen.
Commands that come under the ‘Files’ category are-
- type- This command displays the content of text files.
- mkdir- This command creates a new directory in the system.
- attrib- This command displays the attributes of files.
- copy- This command copies the file.
- move- This command moves the text files.
- replace- This command replaces the file present in our system.
- compact- This command displays and changes the file compression.
- rmdir- This command deletes the directory in our system.
- del- This command deletes one or more files.
- rename- This command renames the file in our system.
- mkdir- This command creates a new directory in the system.
Commands that come under the ‘System’ category are-
- driverquery-It creates a list with all the installed drivers.
- format- This command formats a drive specified by the user.
- label- This command deletes the label of a drive.
- systeminfo- This command provides us with information related to the installation of Windows.
- unlock- This command helps in unlocking the locked drivers.
- backup- This command creates the backup of files present in the system.
Commands that come under the ‘Network’ category are-
1.telnet- This command helps us to establish communication with the other computer.
2. mount- This command helps in enabling the sharing of the network.
3. ftp- This command facilitates the transfer of data from FTP server to PC and vice versa.
4. hostname- This command gives the name of the current host as an output.