first python program

Your First Python Program

To solve any problem, an algorithmic approach must be followed.

This approach is divided into two essential phases:

1- The analysis phase

2- The design phase

We will detail each part of this approach.

1- Analysis phase:


In this phase, we determine three essential elements:

a- The data
b- The desired result
c- The processing

2- Design phase:

It is in this phase that we must write our program, based on the analysis phase.

Example:

We are going to try to write a small program in Python that allows us to calculate the sum of two numbers: a=30 and b=40.

1-Analysis phase:

a- The data: a=30 and b=40

b- The desired result: The sum (s)

C- The processing (or the formula): S=a+b

Practical section

All the programs in our courses are written using “Jupyter Notebook”.

sum python program

Now, we need to display the result on the screen; that’s why we have what’s called an output instruction, “print”.

Output Instruction: Print

The output instruction allows you to either display the contents of a variable or display a message. The keyword used is “print”.

Let x be a variable containing 5 as its value.

To display the value of x, we will write: print(x)

print

To display the message “hello” on the screen, we will write print(‘hello’)

print hello

Let’s return now to our program that calculates the sum of a and b.

To display the result of the sum of a and b, we use the print statement:
print(s)

sum program with print statement

Leave a Comment

Your email address will not be published. Required fields are marked *