Python – Basic Mathematical Programs

Posted

in

by

Tags:

How to perform addition.

# Addend + Addend = Sum
a = 19
b = 15

sum = a + b

print("Total Sum of a and b =",sum)

How to perform subtraction

#Minuend - Subtrahend = Difference

Minuend = 22
Subtrahend = 140

Difference = Minuend - Subtrahend

print("The Difference equals to ",Difference)

How to perform multiplication

# Multiplicand X multiplier = product

Multiplicand = 56
Multiplier = 12

Product = Multiplicand * Multiplier

print("The product of the Multiplicand and mulitplier is ",Product)

How to perform division

# Dividend / Divisor = Quotient (Remainder)

Dividend = 18
Divisor = 5

Quotient = Dividend / Divisor

print("The quotient + reminder = ",Quotient)

How to perform if-else operations

# If-else Python

a = 1
b = 1

if (a < b):
    print("A is Lesser than B")
elif (a ==b):
    print("A is equal to B")
else:
    print("A is Greater than B")

How to perform a while loop operation

# While Loop
# Using While Loop to perform multiplication using Addition

A = 13131313

sum = 0;
counter = 1

while (counter < 11):
    sum = A + sum
    print(A," x ",counter," = ",sum)
    counter = 1 + counter
    

Comments

Leave a Reply

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