DELHI TECHNOLOGICAL UNIVERSITY
PROGRAMMING
USING
PYTHON
A CALCULATOR USING PYTHON
Prepared By: Sarthak Soti(2K21/BAE/134)
Deepti Khurana(2K21/BAE/46)
Prepared For: Dr. Gaganmeet Kaur Awal
DELHI TECHNOLOGICAL UNIVERSITY
02
INDEX
03 - THE PROGRAM
05 - INTRODUCTION
06 - EXPLANATION
06 - OPERATIONS LIST
07 - ADDITION
08 - SUBTRACTION
09 - MULTIPLICATION
10 - DIVISION
11 - REMAINDER
12 - EXPONENTIAL
13 - FACTORISATION
14 - SIMPLE INTEREST
15 - COMPOUND INTEREST
16 - EXITING
DELHI TECHNOLOGICAL UNIVERSITY
03
THE PROGRAM:
DELHI TECHNOLOGICAL UNIVERSITY
04
THE PROGRAM:
DELHI TECHNOLOGICAL UNIVERSITY
05
INTRODUCTION:
In this practical project, we aim to make a
calculator program using the Python
Programming language.
The calculator will take input from the user in
the form of a number and the operation they
want to perform and solve basic arithmetic
problems, find exponents, calculate simple and
compound interest and will also factorise the
number.
DELHI TECHNOLOGICAL UNIVERSITY
06
EXPLANATION:
OPERATIONS LIST:
This is the first part of the code for the calculator
program. This code enlists the various operations
the calculator can perform and gives the user
multiple options he can input to achieve the
desired function. The calculator can perform
basic arithmetic such as addition, subtraction,
multiplication, division, calculating the
remainder, exponent, finding the factors, and
calculating compound interest and simple
interest. Entering ‘ex’ will exit the calculator.
The variable ‘a’ is assigned to store the value
inputted by the user.
DELHI TECHNOLOGICAL UNIVERSITY
07
EXPLANATION:
Output:
ADDITION:
This code is for performing the addition
operation. The ‘if’ statement is used to see what
value was inputted by the user and check if it
matches ‘+’ and execute the code for addition if it
does. Further, when this code is completed, the
user is asked to input two numbers stored as a
float data type in variables x and y. Then the sum
is calculated and stored as a string in the
variable result. Finally, the result is printed.
DELHI TECHNOLOGICAL UNIVERSITY
08
EXPLANATION:
Output:
SUBTRACTION:
This code compares the value inputted by the
user with ‘-’. The following code will be executed
if the value the user inputted matches. The user
will be asked to enter two numbers, and then
their difference will be calculated and stored as a
string value in the variable result. Finally, the
development of this operation will be printed for
the user to see.
DELHI TECHNOLOGICAL UNIVERSITY
09
EXPLANATION:
Output:
MULTIPLICATION:
Here the code compares the value inputted by
the user and checks if it matches *. If it does,
then the block of code is executed. The user is
then asked to input two numbers and the product
is calculated and stored as a variable. After this,
the product Is printed as output for the user.
DELHI TECHNOLOGICAL UNIVERSITY
10
EXPLANATION:
Output:
DIVISION:
This code block first checks whether the value
inputted by the user matches with ‘/’. If it does,
the code gets executed. 2 discounts are accepted
from the user and stored in 2 variables. Then the
result is stored as a string in the variable ‘result’,
and the output is printed for the user.
DELHI TECHNOLOGICAL UNIVERSITY
11
EXPLANATION:
Output:
REMAINDER:
This code is for calculating the remainder. The
code first checks whether the value inputted by
the user matches with ‘%’. Suppose it does, then
the code below it gets executed. The user is
asked to input two values, whose remainder he
wants. Then the rest is calculated using the
Modulo operator (%), and the value is stored as a
string value in the variable ‘result’. Finally, the
result is stored.
DELHI TECHNOLOGICAL UNIVERSITY
12
EXPLANATION:
Output:
EXPONENTIATION:
This code calculates the exponent of a value
entered by the user. First, it checks if the value
entered by the user is ‘exp’. On confirming that it
matches, the user is then asked for a number and
the power he wants to raise the number to. Then
using the power operator (**), the exponent is
calculated and displayed to the user.
DELHI TECHNOLOGICAL UNIVERSITY
13
EXPLANATION:
Output:
FACTORISATION:
This code calculates the factors of a number
entered by the user using a for loop.
The code first checks whether the value inputted
by the user is ‘fr’. Then if it is, the code below it
gets executed. The user has to input the number
he wants to be factorised. They are then using
the for loop and the modulo operator, the code
checks which numbers in the range (1 to x+1)
ultimately divide the value entered by the user.
The range 1 to x+1 includes all values starting
from 1 to the value entered by the user.
DELHI TECHNOLOGICAL UNIVERSITY
14
EXPLANATION:
Output:
SIMPLE INTEREST:
This code checks whether the value inputted by
the user is ‘s’. If it is, the code below gets
executed to calculate the simple interest. The
user is asked to input three values, ie. The
principal amount, the period and the rate of
interest. Then using the simple interest formula,
the interest is calculated and stored as a string in
the variable ‘result’. The answer is then displayed
for the user to see.
DELHI TECHNOLOGICAL UNIVERSITY
15
EXPLANATION:
Output:
COMPOUND INTEREST:
The code here calculates the compound interest.
If the value entered by the user is ‘c’, then he will
be asked to input three values- the principal
amount, the period and the rate of interest. Then
using the compound interests formula, the claim
will be calculated and stored as a string in the
variable ‘result’. Finally, the output will be
displayed.
DELHI TECHNOLOGICAL UNIVERSITY
16
EXPLANATION:
Output:
EXITING:
This is the final code of the calculator. If the user
inputs any value other than those mentioned in
the options list, the program will display a thank
you message and will get terminated using the
quit() command.
Output: