Csc

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

INTRODUCTION

A simple calculator is a basic computational tool designed to perform


fundamental arithmetic operations such as addition, subtraction,
multiplication, and division. Unlike scientific or graphing calculators,
which can handle complex equations and advanced mathematical
functions, a simple calculator focuses solely on essential operations.
Its simplicity makes it user-friendly and ideal for quick, everyday
calculations.

This project involves the development of a simple calculator using


Python, a versatile and beginner-friendly programming language. The
purpose of the project is to create an interactive program where
users can input two numbers and select an operation to perform.
The program will then computer and display the result in a clear and
accessible format.

The simple calculator project is an excellent starting point for


beginners in programming. It provides hands-on experience with
core programming concepts such as handling user input, applying
conditional statements, implementing loops, and defining functions.
By building this project, learners can strengthen their problem-
solving skills and gain confidence in writing Python programs.

In addition to the basic arithmetic operations, the project can be


extended to include additional features, such as error handling for
invalid inputs (e.g., dividing by zero or entering non-numeric data),
performing calculations with multiple numbers, or adding advanced
operations like square roots, powers, or percentages. These
enhancements provide opportunities to explore Python's capabilities
further and build a more robust application.

5
The main objective of this project is to bridge theoretical knowledge
and practical implementation. It demonstrates how to use Python's
built-in capabilities to create a functional and user-friendly
application. Moreover, it highlights the importance of writing clean,
organized, and well-documented code to ensure that the program is
easy to read and maintain.

Overall, the simple calculator project is a foundational step in


learning programming and understanding how to create programs
that solve real-world problems effectively and efficiently.

6
OBJECTIVE
The primary objective of this project is to design and implement a
Python-based simple calculator that performs basic arithmetic
operations such as addition, subtraction, multiplication, and division.
This project aims to provide users with a straightforward and
interactive tool for performing essential mathematical calculations
efficiently and accurately.

Mathematic calculations includes

 Addition:
Addition is one of the four basic arithmetic operations and
is a fundamental feature of any simple calculator. The operation
involves calculating the total or sum of two or more numbers. In the
context of the calculator, users input two numbers, and the program
performs the addition to return the result.

Example:

5+7=12

 Subtraction:
Subtraction is another fundamental arithmetic operation
featured in a simple calculator. It involves finding the difference
between two numbers by deducting the second number from the
first. This operation is commonly used in mathematics and everyday
calculations.

Example:

15−8=7

7
 Multiplication:
Multiplication is one of the essential arithmetic
operations included in a simple calculator. It involves combining
equal groups of a number, effectively scaling one number by
another. This operation is widely used in mathematics, science, and
everyday tasks.

Example:

6×4=24

 Division:
Division is a fundamental arithmetic operation included in
a simple calculator. It involves splitting a number (the dividend) into
equal parts, as determined by another number (the divisor). The
result, called the quotient, shows how many times the divisor fits
into the dividend.

Example:

20÷4=5

8
FLOW CHART

9
SOURCE CODE
import mysql.connector as mc

mycon=mc.connect(host='localhost',username='root',password='roo
t',database='calculator')

cur=mycon.cursor()

def add(user):

no1=int(input('enter no.1:'))

no2=int(input('enter no.2:'))

a=no1+no2

print(a)

q='insert into history values("add",{},{},


{},"{}")'.format(no1,no2,a,user)

cur.execute(q)

def sub(user):

no1=int(input('enter no.1:'))

no2=int(input('enter no.2:'))

a=no1-no2

print(a)

q='insert into history values("sub",{},{},


{},"{}")'.format(no1,no2,a,user)

cur.execute(q)

def multi(user):
10
no1=int(input('enter no.1:'))

no2=int(input('enter no.2:'))

a=no1*no2

print(a)

q='insert into history values("multi",{},{},


{},"{}")'.format(no1,no2,a,user)

cur.execute(q)

def div(user):

no1=int(input('enter no.1:'))

no2=int(input('enter no.2:'))

a=no1/no2

print(a)

q='insert into history values("divi",{},{},


{},"{}")'.format(no1,no2,a,user)

cur.execute(q)

def login(a,b):

cur.execute('select * from users')

data=cur.fetchall()

c=[]

for i in data:

c.append(i)

11
if (a,b) in c:

return('y')

else:

return('n')

print('wrong password/user')

def history(user):

cur.execute('select * from history')

data=cur.fetchall()

for i in data:

if i[4]==user:

print(i)

#Main

user=input('Enter your username:')

password=int(input('Enter your password:'))

p=login(user,password)

while p=='y':

print('enter the number')

print('1.addition')

print('2.subraction')

12
print('3.multiplication')

print('4.devision')

print('5.see history of users')

car=int(input('enter the number:'))

if car == 1:

add(user)

if car == 2:

sub(user)

if car == 3:

multi(user)

if car == 4:

div(user)

p=input('do u want to continue(y/n)')

else:

print('thank you for using')

13
SOURCE CODE IN IDLE:

14
SAMPLE INPUT/OUTPUT
 Addition :

 SUBRACTION :

15
 Multiplication:

 Division:

 History:

16
CONCLUSION
In this project, we have successfully built a simple calculator using
Python, which performs the four basic arithmetic operations:
addition, subtraction, multiplication, and division. The purpose of the
project was to create an interactive tool that allows users to input
two numbers, choose an operation, and obtain the result.
Throughout the development, the project focused on utilizing
Python's core programming features, such as handling user input,
using conditional statements, and implementing basic arithmetic
operators.

The project has been an excellent exercise in understanding and


applying fundamental programming concepts, such as functions,
error handling, and control flow. We implemented robust error-
checking for division by zero, ensuring the program runs smoothly
even when the user inputs problematic values. This practice not only
enhanced the functionality of the calculator but also improved its
user-friendliness by preventing crashes or misbehavior.

Through this simple calculator project, we also gained experience in


creating an efficient, organized code structure, making use of
functions to break down the task into manageable pieces. This
approach is essential when developing more complex software in the
future, as it ensures the code is modular, maintainable, and easy to
debug.

Furthermore, while the project covers only basic operations, it opens


the door for future enhancements. Features such as advanced
mathematical functions (e.g., square roots, powers), graphical user
interfaces (GUIs), or even a history of calculations can be added to
increase the calculator's functionality.
17
In conclusion, this project not only demonstrated the power and
simplicity of Python for solving real-world problems but also laid the
groundwork for more complex programming tasks. It reinforced
important programming concepts and offered a valuable hands-on
experience in building user-interactive applications. Overall, the
calculator is a practical tool that showcases the practical applications
of programming in everyday life.

18
HARDWARE AND SOFTWARE
SOFTWARES:
1. Python
2. MySQL

Hardware:
1. Ram: 4Gb ram(Minimum)
2. Storage: 255Gb(Minimum)
3. Processor: Intel Pentium

19
BIBLIOGRAPHY
CHATGPT- Chatgpt.com

GOOGLE- Google.com

Software used:
1.Python

2. MySQL

20

You might also like