×

How to run a Program in Python

How to run a Program in Python

Writing a program in Python is an easy task, beginners who are ready to kickstart their career in the world of programming can create wonders if they practice basic programs every day.

Python is a simple and easy-to-learn language. The feature that makes it popular is its understandable syntax. So, a person from a non-technical background will also get an idea of what exactly our objective is.

Python is the most preferred language in all the big leading companies which are the tech giants of the IT Industry. Some widely used applications such as YouTube & Dropbox use this language.

Since python is a high-level language there is no need to worry about the details of memory management in the program. Also, it’s interactive in nature so the users can directly execute their chunks of code on the interpreter.

So, the process remains the same, work on building your logic, acquire a good knowledge of the rules that you need to take care of while writing a program, and keep exploring!

Python has a huge library of modules that can provide solutions to complex problems through its in-built components.

Once you have written the code the next step is to execute the program and display the output.

The program we will use to understand the execution is given below-

 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 
  1. 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.
  • Running a program in Python IDLE.

IDLE is Python's Integrated Development & Learning Environment. It works in a similar manner on all the platforms and has this feature of an interactive interpreter.

Moreover, Python IDLE has a shell window and an editor window.

In Python IDLE, each statement is executed and the output is displayed for every line of a program.

  • Running a program in Spyder IDE

Spyder IDE is used for scientific programming in python and it is pre-installed in Anaconda Navigator. Packages like NumPy, matplotlib, scipy, and pandas are integrated with this.

It is used by data analysts, scientists, and engineers. It provides advanced editing options and great visualization tools.

  • The code given below shows how we can perform addition in python. Once you have written the code. Go to the file and click on 'Save As'. Save your file in the destination folder with .py extension.
  • Click on ‘Run’ or F5.

In the output window, you can enter the values and get the output.

  • Running a program in Jupyter Notebook

Jupyter Notebook amalgamates all our work in a manner that it looks well-presented and easy to comprehend. Data Science & Machine Learning projects are mostly made on this platform as new components can be easily integrated with the existing ones. Various processes like reading & fetching data from a file, data cleansing & pre-processing, exploratory data analysis, and visualization can be done on Jupyter Notebook.

Jupyter Notebook is that platform where business problems of different domains can be understood and based on the insights, we can report the required solution.

  • Open Jupyter Notebook
  • Write your code in the provided cells.
  • Once you have written the code, Go to ‘File’ and click on ‘Save As’.
  • Click on ‘Run’ or ‘Shift+Enter’ to run your code.
  • On execution, it will ask you to enter the values.
  • On entering the values, the expected output is displayed.

So, these are the four ways of executing a program in Python. Being a computer geek, we must make an effort to understand the functionality of all the four approaches (Running a program on command prompt, Running a program on Python IDLE, Running a program on Spyder IDE, and Running a program on Jupyter Notebook.)


Related Topics

Python IDE names

Python is one of the most renowned programming languages. It has different execution conditions and a great many compilers to execute the python programs, e.g., PyCharm, PyDev, Jupyter Notebook, Visual...

6 minutes read.

Accuracy_score Function in Sklearn

A crucial stage in data science is measuring our model's performance using the appropriate metric. In this article, we will examine two methods for calculating the accuracy of your predictions:...

13 minutes read.

How to Install Python In Windows

How To Install Python In Windows? Python is a language that every aspirant developer looks forward to. One thing we must keep in our mind is how to begin our hands-on...

3 minutes read.

Excel Automation with Python

Data analysis is the upcoming technology in the IT sector; this data analysis can be performed easily with the help of data frames or by using excel sheets. The data...

4 minutes read.

How to print in the same line in Python?

How to print in the same line in python By default, the print function in Python takes us to the next line and prints the desired statement in the output. In this...

5 minutes read.

Conditional Statements in python

In this article, we will learn about conditional statements and how to apply conditional statements in Python. A decision-making statement is another name for a conditional statement. Decision-making is an important...

5 minutes read.

Android apps for coding in python

Nowadays, it is the generation of smartphones. The world can be seen and acknowledged with a single click on your mobile phone. Everyone uses mobile phones to do any work,...

9 minutes read.

NOT IN operator in Python

This page contains all the information about “not in” operator in python. You can also know everything about what type of operator is “not in” in python language and where...

7 minutes read.

Python Logical Operators

In python, there are many operators which we use in our program. Operators are used in manipulating a particular value or operand. Logical operators are used mainly to evaluate an...

7 minutes read.

Python SciPy Library

Introduction SciPy, a logical library for Python is an open-source, BSD-authorized library for arithmetic, science, and design. The SciPy library relies upon NumPy, which gives advantageous and quick N-dimensional exhibit control....

6 minutes read.

Inheritance in Python

Inheritance in Python Object-Oriented Programming provides reusable patterns to the code for restricting the redundancy in development projects. One of the basic principles of Object-Oriented Programming that helps achieve recyclable code...

8 minutes read.

Python min() function

Python min() function returns you the minimum value element in an iterable. We can also use this function to determine the smallest value among various arguments passed to this function. We...

4 minutes read.

How to uninstall python

To un-install Python, we need to follow different procedures in different operating systems. In this article, we will discuss the un-installation process of Python in Windows, Mac, and Linux operating...

4 minutes read.

Python NewLine

In python, a new line character denoted by "\n" is known as an escape character or escape sequence, and it will force the cursor to change its position to the next...

6 minutes read.

Python Parse Text File

We will learn different ways of read text records in Python. TL;DR The accompanying tells the best way to read all texts from the readme.txt document into a string: with open('readme.txt') as f: lines...

5 minutes read.

Python program to find the area of the triangle

Python program to find the area of the triangle This article will discuss how to find the area of a triangle in Python with all three given sides. The area of...

2 minutes read.

Managing Multiple Python Versions With pyenv

Introduction If you had ever wished to assist to an application that makes use of several different Python versions but weren't sure whether you would quickly test them all? Do you...

4 minutes read.

Python frozenset()

Python frozenset() class The frozenset() class in Python returns a new frozenset object, optionally with elements taken from iterable. Syntax class frozenset([iterable]) Parameter iterable: This parameter represents an iterable object, like list, set, tuple etc. Return This class returns an unchangeable...

1 minute read.

Python Modules

Python Modules The Python module is a collection of definition and statements. It can contain functions, classes, and variables.  Combining the related code into a module makes the code easier to understand and use....

5 minutes read.

Python any() Function

Python any() Function The any() function in Python returns a boolean value ‘True’ if any element of the iterable is true or if the iterable is empty, else it returns False. Syntax any(iterable) Parameter Iterable: An iterable object (list, tuple, dictionary) Return This...

1 minute read.