Computer Science Project

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

0

COMPUTER SCIENCE PROJECT

SIMPLE CALCULATOR

Submitted to: Submitted by:


Ms. Lydia Sumana K P
Senior Secondary Teacher Name - Ojas Taori
Computer Science Department
Class - XI C
Roll No - 19
Subject - Computer Science-083
Session - 2022-2023
1

NATIONAL PUBLIC SCHOOL


ITPL, BENGALURU

DEPARTMENT OF COMPUTER SCIENCE


CERTIFICATE
Certified that the work in this file is the
bonafide work of Ojas Taori of grade XI C
Roll Number 19 recorded in the school
laboratory during the academic year 2022-2023.

Date: 09/01/2023

---------------------------- -------------------------

Teacher in charge External Examiner


School Seal
2

ACKNOWLEDGEMENT

I express my gratitude to Ms. Lydia Sumana K P, my computer science


teacher, for her advice and unwavering support as I worked on my project.
I appreciate my parents and friends for the inspiration and direction necessary,
without which this project would not have been possible.
Finally, I want to thank everyone who was directly or indirectly involved in the
project's successful competition.
3

INDEX

Serial Topic Page No. Teacher’s


No. Signature

1. Bonafide Certificate 1

2. Acknowledgements 2

3. Introduction of the project 4

4. Working environment 5

5. Functions and Module 6

6. Hardware and Software Specification 7

7. Source Code 8

8. Output 13

9. Bibliography 15
4

INTRODUCTION

A calculator is a software capable of performing simple mathematical calculations such as


addition, subtraction, etc. A calculator is used to make it much easier for anyone to calculate
arithmetic and functional mathematical expressions as the computation power and speed of a
computer is far greater than that of a human. The calculator can perform calculations on up to
two inputted numbers depending on the operation. Operations include; Addition, Subtraction,
Multiplication, Division, Exponentiation, Natural Logarithms, Degree to Radians and
Radians to Degree angle converter, Trigonometric functions such as sine, cosine and tangent
and a Factorial generator. This calculator utilises the ‘math’ python module to access certain
mathematical operations and indefinite values.
The user can use the calculator by inputting the name of the desired operator and then
entering required values respectively.
5

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.

Some of Sublime Text’s features are:


GPU RENDERING
TAB MULTI-SELECT
TYPESCRIPT, JSX AND TSX SUPPORT
SUPERPOWERED SYNTAX DEFINITIONS
UPDATED PYTHON API
6

FUNCTIONS AND MODULES

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

HARDWARE AND SOFTWARE SPECIFICATION

SL. Category Minimum Requirement


No.
6.1 Hardware Specification
a. Disk Space 5GB
b. RAM 4GB
c. Central Processing Unit (CPU) x86 64-bit CPU (Intel / AMD
architecture)
d. Keyboard and Mouse Fully functioning keyboard and
mouse
6.2 Software specification
a. Sublime Text Python 3 or higher
b. Modern Operating System Windows 8 or later
Mac OS X 10.13 or higher, 64-bit
Linux:
GLIBC 2.17 (libc.6.so)
GTK 3.10+ (libgtk-3.so, libgdk-3.so)
GLib 2 (libgio-2.0.so)
FreeType 2 (libfreetype.so)
Cairo (libcairo.so)
Pango (libpango-1.0.so)
Pangocairo (libpangocairo-1.0.so)
OpenGL (libGL.so.1)
c. Original Size 60 MB
d. Size on Disk 66 MB
8

SOURCE CODE

#Simple Calculator

"""Python Program to add, subtract, multiply, divide, exponentiate, factorial,


natural log, basic trignometric values and conversion of radians to degrees
and vice versa of given numbers"""

#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

x=float(input("Enter first number:"))


y=float(input("Enter second number:"))
print("Product is:",x*y)

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

x=float(input("Enter an angle in radians:"))


z=math.sin(x)
print("The sine of the angle is:",z)

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

i=str(input("\nEnter the name of selected operation:").lower())


calculate(i,j) #restarts code

#calculator executuion function


def calculate(i,j):
if i=="addition":
add(i,j)
elif i=="subtraction":
sub(i,j)
elif i=="multiplication":
multiply(i,j)
elif i=="division":
divide(i,j)
elif i=="exponent":
exp(i,j)
elif i=="natural log":
logarithm(i,j)
elif i=="sine":
sine(i,j)
elif i=="cosine":
cosine(i,j)
elif i=="tangent":
tangent(i,j)
elif i=="radians to degrees":
deg(i,j)
elif i=="degrees to radians":
rad(i,j)
elif i=="factorial":
facto(i,j)
else:
12

print("Please select a valid operation")


i=str(input("Enter the name of selected operation:").lower())
calculate(i,j) #restarts code

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

You might also like