Computer Science Project
Computer Science Project
Computer Science Project
SIMPLE CALCULATOR
Date: 09/01/2023
---------------------------- -------------------------
ACKNOWLEDGEMENT
INDEX
1. Bonafide Certificate 1
2. Acknowledgements 2
4. Working environment 5
7. Source Code 8
8. Output 13
9. Bibliography 15
4
INTRODUCTION
WORKING ENVIRONMENT
I have used “Sublime Text”, an open source free-to-use text editor used for various computer
programming languages and needs, in order to create the code for this project. In my case it
has been used as an IDLE for Python. IDLE (short for Integrated Development and Learning
Environment) is an integrated development environment for Python, which has been bundled
with the default implementation of the language since 1.5.2b1. IDLE is intended to be a
simple IDE and suitable for beginners, especially in an educational environment. To that end,
it is cross-platform, and avoids feature clutter.
Function
Python Functions is a block of statements that return the specific task. The idea is to put some
commonly or repeatedly done tasks together and make a function so that instead of writing
the same code again and again for different inputs, we can do the function calls to reuse code
contained in it over and over again.
The syntax for a python function is as follows:
In “simple calculator” project, several functions have been defined for various different
mathematical operations each taking an individual input and output. Another function has
been defined to be the main working body of the calculator used to check the condition for
the execution of the user desired function.
Module
A Python module is a file containing Python definitions and statements. A module can define
functions, classes, and variables. A module can also include runnable code. Grouping related
code into a module makes the code easier to understand and use. It also makes the code
logically organized. In order to include a module in our program, we need to ‘import’
modules into our code using the import statement followed by the module name.
Some examples of module are: math, random, calc, etc.
In this project, the inbuilt module ‘math’ has been utilised in order to perform trigonometric
functions, access the indefinite values of the Euler’s number e applied in natural logarithms
and to find the factorial of a number which is a very complex algorithm.
7
SOURCE CODE
#Simple Calculator
#importing module
import math
#interface
print("\t\t\tCALCULATOR\n\n\nPlease select one of the following
operations:\n\nAddition\t\tSubtraction\tMultiplication\tDivision\nExponent\t\tNatural
Log\nSine\t\tCosine\t\tTangent\nRadians to Degrees\tDegreees to Radians\nFactorial")
#dummy variable
i=str()
j=float()
#function definitions
def add(i,j):
x=float(input("Enter first number:"))
y=float(input("Enter second number:"))
print("Sum is:",x+y)
def sub(i,j):
x=float(input("Enter first number:"))
y=float(input("Enter second number:"))
print("Difference is:",x-y)
def multiply(i,j):
9
def divide(i,j):
x=float(input("Enter first number:"))
y=float(input("Enter second number:"))
if y!=0:
print("Quotient is: ",x/y)
else:
print("Error\nNumber must be non-zero")
i=str(input("\nEnter selected operation:").lower())
calculate(i,j) #restarts code
def exp(i,j):
x=float(input("Enter first number:"))
y=float(input("Enter second number:"))
print("First number raised to second is: ",x**y)
def logarithm(i,j):
x=float(input("Enter a number:"))
if x>0:
z=math.log(x)
print("The Log of the number to the base e is:",z)
else:
print("Error\nNumber must be non-zero and positive")
i=str(input("\nEnter the name of selected operation:").lower())
calculate(i,j) #restarts code
def sine(i,j):
10
def cosine(i,j):
x=float(input("Enter an angle in radians:"))
z=math.cos(x)
print("The cosine of the angle is:",z)
def tangent(i,j):
x=float(input("Enter an angle in radians:"))
z=math.tan(x)
print("The tangent of the angle is:",z)
def rad(i,j):
x=float(input("Enter an angle in degrees:"))
z=math.radians(x)
print("The angle in radians is:",z)
def deg(i,j):
x=float(input("Enter an angle in radians:"))
z=math.degrees(x)
print("The angle in degrees is:",z)
def facto(i,j):
x=int(input("Enter a number:"))
if x>=0:
print("Factorial of the number is:",(math.factorial(x)))
else:
print("Error\nNumber must be positive integer")
11
calculate(i,j) #execution
13
OUTPUT
14
15
BIBLIOGRAPHY
geeksforgeeks.org
support.enthought.com/hc/en-us/articles/204273874-Enthought-Python-
Minimum-Hardware-Requirements
sublimetext.com
en.wikipedia.org/wiki/IDLE
python.org