Python Programming

# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
print("This is my 1st program in Python")
# Adding 2 numbers.
num1=8
num2=12
print("The Result = ", num1+num2)
# Branching-1.
num1=8
num2=12
if num1>num2:
print("1st number is greater")
else:
Print("2nd number is greater")
# Branching-2.
mark=33
if mark>=33:
print("Pass")
else:
Print("Fail")

# Branchibg using like ternary oparetor
fee=1500
print('Allowed for Examp')if fee==1500 else print('Not allowed')

# Branchibg using like ternary oparetor
name='Salam Md'
print('Allowed him')if name=='Salam' or name=='Salam md' else print('Not Allowed him')

Share
# Branching-3.
mark=39
if mark>=40:
print("Pass")
elif mark>=20:
print("Referred")
else:
print("Fail")
'''
Mathematical Program using Branching
Here we uses a Menu
Also we take input
'''
print("\t\t\tMathematical Program")
print("\t\t ---------------------")
print("\t\t 1. Add")
print("\t\t 2. Subtract")
print("\t\t 3. Multiply")
print("\t\t 4. Divide")
print("\t\t 5. Exit")
ch=input("\t Enter your choice=")
if(ch=='1'):
num1=int(input("\t Enter 1st number ="))
num2=int(input("\t Enter 2nd number ="))
print("\t\t Result = ", num1+num2)
if(ch=='2'):
num1=int(input("\t Enter 1st number ="))
num2=int(input("\t Enter 2nd number ="))
print("\t\t Result = ", num1-num2)
if(ch=='3'):
num1=int(input("\t Enter 1st number ="))
num2=int(input("\t Enter 2nd number ="))
print("\t\t Result = ", num1*num2)
if(ch=='4'):
num1=int(input("\t Enter 1st number ="))
num2=int(input("\t Enter 2nd number ="))
print("\t\t Result = ", num1/num2)
if(ch=='5'):
exit
print("\t\t Thanks")
# Looping-2. (1+2+3.............+100)
sum=0
for x in range(1, 101, 1):
sum=sum+x
print("The Sum = ", sum)
# Looping-3. (1+2+3.............+100) add for even number
sum=0
for x in range(0, 101, 2):
sum=sum+x
print("The Sum = ", sum)
# Looping-1. (1+2+3.............+100) add for odd number
sum=0
for x in range(1, 101, 2):
sum=sum+x
print("The Sum = ", sum)
# Function()
def purchase_misty():
s=0
for x in range(0, 101, 2):
s=s+x
print("The Sum = ", s+5)
# Call the function
purchase_misty()

example: sum_even
Algorithm:
A set of rules that defines how a program executes. Algorithms are used in computer science and mathematics. They are made up of three basic building blocks: sequencing, selection, and iteration.

#Algorithm for Python Program to Add Two Numbers:
1. Declare two variables.
2. Initialize the variables with some values.
3. Declare another variable to store the sum of the numbers.
4. Apply the mathematical plus(+) operator between two values and
5. store the result.

Algorithm:
Name of Algorithm: To add two numbers.

Step 1: Start
Step 2: Read two numbers as A and B
Step 3: Sum = A + B
Step 4: Display Sum
Step 5: Stop
Flowchart:
A flowchart is a graphical representation of the steps a program takes to process data. In this, we can use several geometric patterns to illustrate the numerous actions the program carries out.

Flowchart:
flowchart sum two numbers
Difference between algorithm and flow chart:

1. An algorithm is a step-by-step procedure to solve a problem. A flowchart is a diagram created with different shapes to show the flow of data.
2. The algorithm is complex to understand. A flowchart is easy to understand.
3. In the algorithm, plain text is used. In the flowchart, symbols/shapes are used.

The flowchart for finding Greatest among three numbers is given below:-

Flowchart
Flowchart to calculate area of triangle