Calculator Project Report 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

PROJECT REPORT

ON
CALCULATOR

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING

CEC, LANDRAN MOHALI, PUNJAB

SUBMITTED TO: SUBMITTED BY:

Mr. Aanchal Singh Suraj Sharma


Rohit Kumar
Sunil
Vishal
Sunny
Subiksha
B.Tech ECE(8th Sem)
Acknowledgement:-
ABSTRACT:

This work was centered on the Design and


implementation of a simple scientific calculator for
education organization. The  study traced calculator
system as a tool to completely change mathematical
knowledge and sophisticated problems solving strategies
had advanced the field of simulated engine in
Mathematical.
This project work also focused principally on  numbers
and arithmetic operation. This researcher investigated the
manual system in detail with a view to finding out the
need to automate the system.
Interestingly, the end result of simple calculator system
was its ability to process number and operators, and
provides a useful result.
Therefore, this project will help immensely in the
following way. Easy calculating of tedious mathematical
problems, easy to retrieval of errors and it will also be of
a good assistance to any researcher on these topics.

Chapter No. 1:- Introduction to Project


1.1 Project Description:-  A calculator is a device
that performs arithmetic operations on numbers. The
simplest calculators can do only addition, subtraction,
multiplication, and division. More sophisticated
calculators can handle exponent ial operations, roots,
logarithm s, trigonometric functions, and hyperbolic
functions. Internally, some calculators actually perform
all of these functions by repeated processes of addition.
Most calculators these days require electricity to operate.
Portable, battery-powered calculators are popular with
engineers and engineering students. Before 1970, a more
primitive form of calculator, the slide rule , was
commonly used. It consisted of a slat of wood, called the
slide, that could be moved in and out of a reinforced pair
of slats. Both the slide and the outer pair of slats had
calibrated numerical scales. A movable, transparent
sleeve called the cursor was used to align numerals on
the scales. The slide rule did not require any source of
power, but its precision was limited, and it was necessary
to climb a learning curve to become proficient with it.
One of the most primitive calculators, the abacus is still
used in some regions of the Far East. The abacus uses
groups of beads to denote numbers. Like the slide rule,
the abacus requires no source of power. The beads are
positioned in several parallel rows, and can be moved up
and down to denote arithmetic operations. It is said that a
skilled abacus user can do some calculations just as fast
as a person equipped with a battery-powered calculator.
As calculators became more advanced during the 1970s,
they became able to make computations involving
variables (unknowns). These were the first personal
computers. Today's personal computers can still perform
such operations, and most are provided with a virtual
calculator program that actually looks, on screen, like a
handheld calculator. The buttons are actuated by pointing
and clicking.
Theoretically, a modern computer is a calculator that
works with binary numbers and has a much larger
memory. But in the practical sense, a computer is far
more than a mere calculator, because of the wide variety
of non-computational tasks it can perform.
A calculator is a person who performs arithmetic or other
mathematical calculations.

1.2 Scope of Project:- The technology is booming,


and modern innovations and technology has changed our
lives. There is a huge debate in our society, whether
students should be allowed to use a calculator from such
a young age. 

This technology allows students solve complicated


problems quickly and in an efficient manner.
Additionally, it can reduce the problem to simpler tasks
and allows the student to devote more time in
understanding the problem. Secondly, they are saved
from monotonous calculations and the same boring
mundane procedure.
The above advantages help students to avoid boredom,
and it does not demoralize their mathematical
understanding. If mathematics is not made entertaining,
pupils can feel bored, and it can demoralize their
mathematical understanding.
Thirdly, when teachers realize that the mathematical
capacity of some of their pupils are not so great, using
this handheld device or the online calculator platforms,
helps them manage addition, subtraction, multiplication
and division problems in an efficient manner.
Most handheld or online calculators are relatively cheap,
various designs and functionality suitable for various
budgets. They are also inexpensive to maintain once
handled with care.

1.3 Purpose Of the Project:-The prime purpose of a


calculator is to provide a calculated result in response to
a given set of input parameters. These systems are used
in a ‘session’ mode. The user enters values for a number
of parameters and a calculation/evaluation is performed.
The user may then adjust the variable input parameters,
and request that the calculation be performed again. This
can occur numerous times until the user has obtained the
information required and chooses to terminate the
session.
Most calculators share the following characteristics:
The prime objective of the calculator is to perform a
number of calculations in response to user supplied
input. The possible number of calculations is pre-
defined. The results of the calculations may be presented
in summary or detailed format. It is these outputs that are
the main business functions of the calculator. The
calculation and results presentation are sub processes of
the one elementary process.
The user enters data into a series of screens, which
exhibit all the standard GUI screen features. For
example, drop down list boxes to assist with user
parameter selection, on-line validation of data,
mandatory and optional fields and other features
available in a GUI interface.
Data entered may be stored permanently (indefinite
persistence), exist only for the duration of the session
(short persistence), or in a very simple calculator may
need to be re-entered each time the calculation is
triggered (no persistence)
The databases used by calculators may be very simple.
For example one large physical file may store all the data
input by the user. It is recommended that the contents of
the file be examined closely and the guidelines for
identifying logical files applied, See Section 3.4 Files.
One large physical file may comprise more than one
logical file.
The calculations are triggered once the user has supplied
all the necessary information.
The results of the calculation/evaluation are presented
either as:
A single result
A results table, for example a schedule of repayments
A graph
The results are presented on screen and, if required a
hard copy may be produced.
The user is able to adjust the variable input parameters as
many times as required, each time triggering the
calculations. The changed parameter values are stored.
The data entry and calculation functions are usually
supported by a number of reference tables which define
products, interest rates, calendars and other values that
are needed as input to the calculations.
1.4 Software Requirement :-

1.4.1 Environment Required - Window 10

1.4.2 Language Requirement - Python

1.4.3 GUI Requirement - Tkinter

1.4.4 IDE Requirement - Pycharm


1.4.1 Environment Required -

Window 10 :-
An operating system is a powerful and usually extensive
program that controls and manages the hardware and
other software on a computer.
All computers and computer-like devices require
operating systems, including your laptop, tablet, desktop,
smartphone, smartwatch, and router.
Examples of Operating Systems
Laptops, tablets, and desktop computers all run operating
systems. You've probably heard of most of them. Some
examples include versions of Microsoft Windows
(like Windows 11, Windows 10, Windows 8, Windows
7, Windows Vista, and Windows XP),
Apple's macOS (formerly OS X), Chrome OS, and
various Unix and Linux distribution lists. (Unix and
Linux are open-source operating systems.)
Windows 10 is the latest operating system from
Microsoft for personal computers. Officially unveiled in
2014 it introduced the idea of rolling updates to the
operating system.
Microsoft has successfully dominated the personal
computer operating system for decades and its latest
version, Windows 10, looks likely to carry on this market
control.
Windows 10 was released to consumers on the 29th of
July 2015 as the successor to Windows 9. This latest
version of the Windows operating system introduced
what the company called “universal apps”, apps that are
developed to work on smartphones, personal computers,
video game consoles, and HoloLens.

1.4.2 Language Required:-

Python:- Python is a high-level, interpreted, interactive


and object-oriented scripting language. Python is
designed to be highly readable. It uses English keywords
frequently where as other languages use punctuation, and
it has fewer syntactical constructions than other
languages.

python is a must for students and working professionals


to become a great Software Engineer specially when they
are working in Web Development Domain. I will list
down some of the key advantages of learning Python:

Python is Interpreted − Python is processed at runtime by


the interpreter. You do not need to compile your program
before executing it. This is similar to PERL and PHP.
Python is Interactive − You can actually sit at a Python
prompt and interact with the interpreter directly to write
your programs.

Python is Object-Oriented − Python supports Object-


Oriented style or technique of programming that
encapsulates code within objects.

Python is a Beginner's Language − Python is a great


language for the beginner-level programmers and
supports the development of a wide range of applications
from simple text processing to WWW browsers to
games.

Characteristics of Python:-
Following are important characteristics of Python
Programming −

It supports functional and structured programming


methods as well as OOP.

It can be used as a scripting language or can be compiled


to byte-code for building large applications.
It provides very high-level dynamic data types and
supports dynamic type checking.

It supports automatic garbage collection.

It can be easily integrated with C, C++, COM, CORBA,


and Java.

Applications of Python:-
As mentioned before, Python is one of the most widely
used language over the web. I'm going to list few of them
here:
Easy-to-learn − Python has few keywords, simple
structure, and a clearly defined syntax. This allows the
student to pick up the language quickly.

Easy-to-read − Python code is more clearly defined and


visible to the eyes.
Easy-to-maintain − Python's source code is fairly easy-
to-maintain.
A broad standard library − Python's bulk of the library
is very portable and cross-platform compatible on UNIX,
Windows, and Macintosh.

Interactive Mode − Python has support for an


interactive mode which allows interactive testing and
debugging of snippets of code.

Portable − Python can run on a wide variety of hardware


platforms and has the same interface on all platforms.

Extendable − You can add low-level modules to the


Python interpreter. These modules enable programmers
to add to or customize their tools to be more efficient.

Databases − Python provides interfaces to all major


commercial databases.

GUI Programming − Python supports GUI applications


that can be created and ported to many system calls,
libraries and windows systems, such as Windows MFC,
Macintosh, and the X Window system of Unix.
1.4.3 GUI Required :-
Python provides various options for developing graphical
user interfaces (GUIs). Most important are listed below.

Tkinter − Tkinter is the Python interface to the Tk GUI


toolkit shipped with Python. We would look this option
in this chapter.

wxPython − This is an open-source Python interface for


wxWindows http://wxpython.org.

JPython − JPython is a Python port for Java which gives


Python scripts seamless access to Java class libraries on
the local machine http://www.jython.org

Tkinter:- Python offers various utilities to design the


GUI wiz Graphical User Interface, and one such utility is
Tkinter which is most commonly used. It is indeed one
of the fastest and easiest ways to build GUI application.
Moreover, Tkinter is cross-platform, hence the same
code works on mac OS, Windows, and Linux.

Tkinter is the standard GUI library for Python. Python


when combined with Tkinter provides a fast and easy
way to create GUI applications. Tkinter provides a
powerful object-oriented interface to the Tk GUI toolkit.
Creating a GUI application using Tkinter is an easy task.
All you need to do is perform the following steps −

Import the Tkinter module.

Create the GUI application main window.

Add one or more of the above-mentioned widgets to the


GUI application.

Enter the main event loop to take action against each


event triggered by the user.

Tkinter Widgets
Tkinter provides various controls, such as buttons, labels
and text boxes used in a GUI application. These controls
are commonly called widgets.
There are currently 15 types of widgets in Tkinter. We
present these widgets as well as a brief description in the
following table −
Button-
The Button widget is used to display buttons in your
application.
Canvas-
The Canvas widget is used to draw shapes, such as lines,
ovals, polygons and rectangles, in your application.
Checkbutton-
The Checkbutton widget is used to display a number of
options as checkboxes. The user can select multiple
options at a time.

Standard attributes
Let us take a look at how some of their common
attributes.such as sizes, colors and fonts are specified.

-Dimensions

-Colors

-Fonts
-Anchors

-Relief styles

-Bitmaps

-Cursors

1.4.4 IDE Required:-

PyCharm:- PyCharm is a dedicated Python Integrated


Development Environment (IDE) providing a wide range
of essential tools for Python developers, tightly
integrated to create a convenient environment for
productive Python, web, and data science development.

PyCharm is available in three editions:

Community (free and open-sourced): for smart and


intelligent Python development, including code
assistance, refactorings, visual debugging, and version
control integration.
Professional (paid) : for professional Python, web, and
data science development, including code assistance,
refactorings, visual debugging, version control
integration, remote configurations, deployment, support
for popular web frameworks, such as Django and Flask,
database support, scientific tools (including Jupyter
notebook support), big data tools.

Edu (free and open-sourced): for learning programming


languages and related technologies with integrated
educational tools.

Start with a project in PyCharm


Everything you do in PyCharm, you do within the
context of a project. It serves as a basis for coding
assistance, bulk refactoring, coding style consistency,
and so on. You have three options to start working on a
project inside the IDE:

Open an existing project

Check out a project from version control

Create a new project


Chapter No. 2:-

Python Calculator Project:-

Step 1: Importing the necessary modules:-

- To use the Tkinter we need to import the Tkinter


module. We are also going to import the function
factorial from math module.

Code:-
from tkinter import *
import parser
from math import factorial

Step 2: Making a window for our calculator


Now we are going to draft the window for our calculator
which will accommodate the buttons.
Code:
root = Tk()
root.title('DataFlair - Calculator')
root.mainloop()

Explanation:-
The above code sets the title of python calculator
window as ‘DataFlair – Calculator’. When you run the
above code, you will get a window like this.

Step 3: Designing the buttons


Now let’s quickly design the buttons for our calculator
and put them on our application window.
Code:

'''
Buttons
'''

button_7 = Button(tk_calc, button_params_main,


text='7',
command=lambda:button_click('7')).grid(row=6,
column=0, sticky="nsew")
button_8 = Button(tk_calc, button_params_main,
text='8',

command=lambda:button_click('8')).grid(row=6,
column=1, sticky="nsew")
button_9 = Button(tk_calc, button_params_main,
text='9',

command=lambda:button_click('9')).grid(row=6,
column=2, sticky="nsew")
delete_one = Button(tk_calc, bd=5, fg='#000',
font=('sans-serif', 20, 'bold'),
text='DEL', command=button_delete,
bg='#293C4A').grid(row=6, column=3, sticky="nsew")
delete_all = Button(tk_calc, bd=5, fg='#000', font=('sans-
serif', 20, 'bold'),
text='AC', command=button_clear_all,
bg='#293C4A').grid(row=6, column=4, sticky="nsew")

button_4 = Button(tk_calc, button_params_main,


text='4',

command=lambda:button_click('4')).grid(row=7,
column=0, sticky="nsew")
button_5 = Button(tk_calc, button_params_main,
text='5',

command=lambda:button_click('5')).grid(row=7,
column=1, sticky="nsew")
button_6 = Button(tk_calc, button_params_main,
text='6',

command=lambda:button_click('6')).grid(row=7,
column=2, sticky="nsew")
mul = Button(tk_calc, button_params_main, text='*',
command=lambda:button_click('*')).grid(row=7,
column=3, sticky="nsew")
div = Button(tk_calc, button_params_main, text='/',
command=lambda:button_click('/')).grid(row=7,
column=4, sticky="nsew")

button_1 = Button(tk_calc, button_params_main,


text='1',

command=lambda:button_click('1')).grid(row=8,
column=0, sticky="nsew")
button_2 = Button(tk_calc, button_params_main,
text='2',
command=lambda:button_click('2')).grid(row=8,
column=1, sticky="nsew")
button_3 = Button(tk_calc, button_params_main,
text='3',

command=lambda:button_click('3')).grid(row=8,
column=2, sticky="nsew")
add = Button(tk_calc, button_params_main, text='+',
command=lambda:button_click('+')).grid(row=8,
column=3, sticky="nsew")
sub = Button(tk_calc, button_params_main, text='-',
command=lambda:button_click('-')).grid(row=8,
column=4, sticky="nsew")

button_0 = Button(tk_calc, button_params_main,


text='0',

command=lambda:button_click('0')).grid(row=9,
column=0, sticky="nsew")
point = Button(tk_calc, button_params_main, text='.',

command=lambda:button_click('.')).grid(row=9,
column=1, sticky="nsew")
exp = Button(tk_calc, button_params_main, text='EXP',
font=('sans-serif', 16, 'bold'),
command=lambda:button_click(E)).grid(row=9,
column=2, sticky="nsew")
equal = Button(tk_calc, button_params_main, text='=',
command=button_equal).grid(row=9,
columnspan=2, column=3, sticky="nsew")

Explanation:
In this calculator program in python, the “Entry”
function helps in making a text input field and we
use .grid() method to define the positioning associated
with the button or input field. We use the button method
to display a button on our application window.

root – the name with which we refer to our window


text – text to be displayed on the button
row – row index of the grid
column – column index of the grid
columnspan – spans or combines the number of columns
sticky – If the resulting cell is larger than the widget then
sticky defines how to expand the widget. The
combination of constants used S, N, E, and W, or NW,
NE, SW, and SE are analogous to the directions in
compass. N+E+W+S means that the widget should be
expanded in all directions

Step 4: Text Display

# Function to add in the entry of text display


def button_click(char):
global calc_operator
calc_operator += str(char)
text_input.set(calc_operator)

# Function to clear the whole entry of text display


def button_clear_all():
global calc_operator
calc_operator = ""
text_input.set("")

# Function to delete one by one from the last in the entry


of text display
def button_delete():
global calc_operator
text = calc_operator[:-1]
calc_operator = text
text_input.set(text)

To create a Tkinter :
 
Importing the module – tkinter
Create the main window (container)
Add any number of widgets to the main window
Apply the event Trigger on the widgets.
Complete code:-

from tkinter import *

# Function to add in the entry of text display


def button_click(char):
global calc_operator
calc_operator += str(char)
text_input.set(calc_operator)

# Function to clear the whole entry of text display


def button_clear_all():
global calc_operator
calc_operator = ""
text_input.set("")

# Function to delete one by one from the last in the entry


of text display
def button_delete():
global calc_operator
text = calc_operator[:-1]
calc_operator = text
text_input.set(text)
# Funtion to find the result of an operation
def button_equal():
global calc_operator
temp_op = str(eval(calc_operator))
text_input.set(temp_op)
calc_operator = temp_op

tk_calc = Tk()
tk_calc.configure(bg="#db701f", bd=10)
tk_calc.title("Sunil's Calculator")

calc_operator = ""
text_input = StringVar()

text_display = Entry(tk_calc, font=('sans-serif', 20,


'bold'), textvariable=text_input,
bd=5, insertwidth = 5, bg='#BBB',
justify='right').grid(columnspan=5, padx = 10, pady =
15)

button_params = {'bd':5, 'fg':'#BBB', 'bg':'#3C3636',


'font':('sans-serif', 20, 'bold')}
button_params_main = {'bd':5, 'fg':'#000', 'bg':'#BBB',
'font':('sans-serif', 20, 'bold')}

'''
Buttons
'''

button_7 = Button(tk_calc, button_params_main,


text='7',

command=lambda:button_click('7')).grid(row=6,
column=0, sticky="nsew")
button_8 = Button(tk_calc, button_params_main,
text='8',

command=lambda:button_click('8')).grid(row=6,
column=1, sticky="nsew")
button_9 = Button(tk_calc, button_params_main,
text='9',
command=lambda:button_click('9')).grid(row=6,
column=2, sticky="nsew")
delete_one = Button(tk_calc, bd=5, fg='#000',
font=('sans-serif', 20, 'bold'),
text='DEL', command=button_delete,
bg='#293C4A').grid(row=6, column=3, sticky="nsew")
delete_all = Button(tk_calc, bd=5, fg='#000', font=('sans-
serif', 20, 'bold'),
text='AC', command=button_clear_all,
bg='#293C4A').grid(row=6, column=4, sticky="nsew")

button_4 = Button(tk_calc, button_params_main,


text='4',

command=lambda:button_click('4')).grid(row=7,
column=0, sticky="nsew")
button_5 = Button(tk_calc, button_params_main,
text='5',

command=lambda:button_click('5')).grid(row=7,
column=1, sticky="nsew")
button_6 = Button(tk_calc, button_params_main,
text='6',

command=lambda:button_click('6')).grid(row=7,
column=2, sticky="nsew")
mul = Button(tk_calc, button_params_main, text='*',
command=lambda:button_click('*')).grid(row=7,
column=3, sticky="nsew")
div = Button(tk_calc, button_params_main, text='/',
command=lambda:button_click('/')).grid(row=7,
column=4, sticky="nsew")

button_1 = Button(tk_calc, button_params_main,


text='1',

command=lambda:button_click('1')).grid(row=8,
column=0, sticky="nsew")
button_2 = Button(tk_calc, button_params_main,
text='2',

command=lambda:button_click('2')).grid(row=8,
column=1, sticky="nsew")
button_3 = Button(tk_calc, button_params_main,
text='3',

command=lambda:button_click('3')).grid(row=8,
column=2, sticky="nsew")
add = Button(tk_calc, button_params_main, text='+',
command=lambda:button_click('+')).grid(row=8,
column=3, sticky="nsew")
sub = Button(tk_calc, button_params_main, text='-',
command=lambda:button_click('-')).grid(row=8,
column=4, sticky="nsew")

button_0 = Button(tk_calc, button_params_main,


text='0',

command=lambda:button_click('0')).grid(row=9,
column=0, sticky="nsew")
point = Button(tk_calc, button_params_main, text='.',

command=lambda:button_click('.')).grid(row=9,
column=1, sticky="nsew")
exp = Button(tk_calc, button_params_main, text='EXP',
font=('sans-serif', 16, 'bold'),
command=lambda:button_click(E)).grid(row=9,
column=2, sticky="nsew")
equal = Button(tk_calc, button_params_main, text='=',
command=button_equal).grid(row=9,
columnspan=2, column=3, sticky="nsew")
tk_calc.mainloop()

Output:-

You might also like