You are on page 1of 20

Programming With Python

Microproject
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MICROPROJECT
Academic Year: 2023-2024

Topic:- To create a simple calculator using classes and


objects in python
Program:- Computer Engineering.
Subject Name:- Programming with Python
Course code:- 22616

Course:- CO6I

Prof. Prof. PROF.

[Name of Guide] [Name of HOD] [Principal]


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
CERTIFICATE

This is to certify that Mr. Roll No: of TYCO of Diploma in Computer


Engineering of Institute: MIT Polytechnic Pune (Code: 0148) has
completed the Micro Project satisfactorily in Subject: Programming
with Python For the academic year 2023-2024 as prescribed in the
curriculum.

Place :Pune Enrollment No:

Date: Exam. Seat No: --------

Subject Teacher Head of the Department Principal

(Prof. ) (Prof.) (Prof .)

Institute

Seal
ndex

Sr.No Content Page No.

1. Abstract 1

2. Introduction 2

3. Actual method 4

4. Program 6

5. Output of the project 8

6. Literature Survey 9

7. Micro-Project Proposal A 11

8. Micro-Project Proposal B 13

9. Conclusion 14

10. Evaluation Sheet 15


To create a simple calculator using classes and objects in python

1.0 ABSTSRACT

The Python program utilizes object-oriented programming principles to


implement a simple calculator using classes and objects. The program defines a
`Calculator` class that encapsulates basic arithmetic operations such as addition,
subtraction, multiplication, and division. Each arithmetic operation is
implemented as a method within the `Calculator` class, allowing for modular
and reusable code.

Upon instantiation of the `Calculator` class, an instance of the calculator object


is created, enabling users to perform arithmetic operations on two input
numbers. The program prompts the user to enter two numerical values and
select an operation from a menu of options. Based on the user's choice, the
corresponding method of the `Calculator` class is invoked to execute the
selected operation.

Through the implementation of classes and objects, the program promotes code
organization, encapsulation, and abstraction. It separates the calculator's
functionality from the user interface, enhancing modularity and maintainability.
By adhering to object-oriented principles, the program demonstrates a
structured and efficient approach to building a simple calculator in Python.

1|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

2.0 Introduction
WHAT IS Class and Objects in python ?
Classes:- In Python, a class is a user-defined data type that contains both the
data itself and the methods that may be used to manipulate it. In a sense, classes
serve as a template to
create objects. They provide the characteristics and operations that the objects
will employ.

Suppose a class is a prototype of a building. A building contains all the details


about the floor, rooms, doors, windows, etc. we can make as many buildings as
we want, based on these details. Hence, the building can be seen as a class, and
we can create as many objects of this class.

Syntax

1. class ClassName:
2. #statement_suite

In Python, we must notice that each class is associated with a documentation


string which can be accessed by using <class-name>.__doc__. A class contains
a statement suite including fields, constructor, function, etc. definition.

Example:

Code:

1. class Person:
2. def __init__(self, name, age):
3. # This is the constructor method that is called when creating a new P
erson object
4. # It takes two parameters, name and age, and initializes them as attri
butes of the object
5. self.name = name
6. self.age = age
7. def greet(self):
8. # This is a method of the Person class that prints a greeting message
9. print("Hello, my name is " + self.name)
2|MIT Polytechnic Pune
To create a simple calculator using classes and objects in python

Name and age are the two properties of the Person class. Additionally, it has a
function called greet that prints a greeting.

Object:- An object is a particular instance of a class with unique characteristics


and functions. After a class has been established, you may make objects based
on it. By using the class constructor, you may create an object of a class in
Python. The object's attributes are initialised in the constructor, which is a
special procedure with the name __init__.

Syntax:

1. # Declare an object of a class


2. object_name = Class_Name(arguments)

Example:

Code:

1. class Person:
2. def __init__(self, name, age):
3. self.name = name
4. self.age = age
5. def greet(self):
6. print("Hello, my name is " + self.name)
7.
8. # Create a new instance of the Person class and assign it to the variable p
erson1
9. person1 = Person("Ayan", 25)
10. person1.greet()

3.0 Actual Methodology Followed:

INTRODUCTION:
3|MIT Polytechnic Pune
To create a simple calculator using classes and objects in python

Define the Calculator Class: Create a class named Calculator to encapsulate the
calculator's functionality.
Add Basic Arithmetic Methods: Implement methods within the Calculator class
for addition, subtraction, multiplication, and division operations.
Create a Main Function: Define a main() function to serve as the entry point of
the program.
Instantiate the Calculator Class: Inside the main() function, create an instance of
the Calculator class.
Display User Menu: Prompt the user to input two numbers and select an
operation from a menu of options.
Perform the Chosen Operation: Based on the user's choice, call the
corresponding method of the Calculator class to perform the operation on the
input numbers.
Display the Result: Print the result of the operation to the user.
Handle Invalid Inputs: Provide error handling to handle invalid user inputs
gracefully.
Continue Execution: Allow the program to continue executing until the user
chooses to exit.

 How it work?
The work of a calculator program in Python involves performing basic
arithmetic operations such as addition, subtraction, multiplication, and division
on user-provided numbers. Here's how the calculator program typically works:

1. User Input : The program prompts the user to enter two numbers and
select an operation (addition, subtraction, multiplication, or division).

2. Operation Execution : Based on the user's choice, the program performs


the corresponding arithmetic operation using the input numbers.

4|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

3. Result Display : After performing the operation, the program displays the
result to the user.

4. Error Handling : The program handles potential errors such as invalid


inputs (e.g., non-numeric values) or division by zero gracefully.

5. Looping or Exiting : The program may continue running and prompt the
user for additional calculations, or it may allow the user to exit the program.

4.0 Program Of Project :

5|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

class Calculator:
def __init__(self):
pass

def add(self, x, y):


return x + y

def subtract(self, x, y):


return x - y

def multiply(self, x, y):


return x * y

def divide(self, x, y):


if y != 0:
return x / y
else:
return "Cannot divide by zero"

# Create an instance of the Calculator class


calc = Calculator()

# Perform operations
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")

choice = input("Enter choice (1/2/3/4):")

if choice == '1':
print("Result:", calc.add(num1, num2))

elif choice == '2':


print("Result:", calc.subtract(num1, num2))

6|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

elif choice == '3':


print("Result:", calc.multiply(num1, num2))

elif choice == '4':


print("Result:", calc.divide(num1, num2))

else:
print("Invalid input")

7|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

5.0 Output of the project :

8|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

6.0 Literature Survey :

A literature survey for creating a simple calculator using classes and objects in
Python involves exploring a variety of resources to gain insights into object-
oriented programming (OOP) principles and calculator implementations. The first
step in the survey is to consult the official Python documentation, which provides
comprehensive information on classes, objects, and basic arithmetic operations.
Additionally, online tutorials and books covering OOP fundamentals in Python
offer step-by-step guidance and practical examples for beginners and intermediate
learners. These resources help establish a solid understanding of class definition,
instance creation, method invocation, and other OOP concepts crucial for
building a calculator application.

Furthermore, seeking out specific examples or tutorials focused on creating a


calculator using classes and objects in Python offers valuable hands-on
experience. These resources typically provide code snippets, explanations, and
design consideration s for implementing arithmetic operations within a class-
based structure. Reviewing multiple examples allows learners to compare
different approaches, coding styles, and design patterns, fostering a deeper
understanding of OOP principles and their practical applications.

Educational articles, blog posts, and video tutorials aimed at Python


programmers often cover topics related to classes, objects, and arithmetic
operations. These resources offer explanations, demonstrations, and practical
examples to help learners grasp fundamental concepts and apply them
effectively in real-world scenarios. Additionally, exploring code repositories
such as GitHub provides access to open-source projects and sample code for
calculator implementations in Python. Analyzing existing implementations
allows learners to study coding techniques, design patterns, and best practices
employed by experienced developers.

9|MIT Polytechnic Pune


To create a simple calculator using classes and objects in python

 References :
1.Student, Bachelors of Computer Application, “LIBRARY
MANAGEMENT SYSTEM ” Aakar College Of Management For
Women, Hingna, Nagpur, Maharashtra, India 2023 IJARIIE-ISSN(O)-
2395-4396 .

2.https://www.scribd.com/document/512994961/Micro-project-Simple-
Calculator-System-Python-1.

10 | M I T P o l y t e c h n i c P u n e
To create a simple calculator using classes and objects in python

Micro-Project Proposal-A

❖ Project Problem Statement/title:- To create a simple calculator using


classes and objects in python

1.0 Brief Introduction: For straightforward mathematical calculations in


Python, you can use the built-in mathematical operators, such as addition ( + ),
subtraction ( - ), division ( / ), and multiplication ( * ). But more advanced
operations, such as exponential, logarithmic, trigonometric, or power functions,
are not built in.

2.0 Aim of the Micro-Project : The aim of the calculator project in


Python is to create a simple yet functional tool that allows users to perform
basic arithmetic operations such as addition, subtraction, multiplication, and
division. It serves as an educational exercise to practice programming
fundamentals and develop problem-solving skills.
.
3.0 Action Plan:--
Sr Details of activity Planned Planned Name of
No Finis
Start Responsible team
. h
Date
Date member

1. Finalising the Topic 5/01/24 5/01/24


and Allotment of
Work.
2. Searching 05/01/24 05/01/24 Verified by All
Information.
3. Arranging the 06/01/24 07/01/24
collected information.
4. Proofreading the 17/01/24 19/01/24
Information.
5. Surveying 19/01/24 22/01/24
Information

11 | M I T P o l y t e c h n i c P u n e
To create a simple calculator using classes and objects in python

6. Requiremen 29/01/24 29/01/24


t Analysis
7. Finalizing Layout 15/02/24 16/02/24

8. Generating 26/02/24 28/02/24


Program and Final
Execution

9. Report Generation 04/03/24 04/03/24

10. Final submission 26/03/24 26/03/24 Verified by All &Submitted

4.0 Resources required :-

Sr.No Name of Specification Quantity Remark


. Resources/ma
terial
1. Computer System 12 GB RAM, 1
Windows 11
OS
2. Software Python 3.7

3. Other resources internet

12 | M I T P o l y t e c h n i c P u n e
To create a simple calculator using classes and objects in python

Micro-Project Proposal-B

❖ Project Problem Statement/title:- To create a simple calculator using


classes and objects in python

1.0 Course outcome : 1.Implement of python code.


2. Understanding of Basic Programming Concepts:.
3. Application of Object-Oriented Programming Principles:
4. Programming Fundamentals:

2.0 Brief Introduction Add Basic Arithmetic Methods: Implement


methods within the Calculator class for addition, subtraction, multiplication,
and division operations. Create a Main Function: Define a main() function to
serve as the entry point of the program.

3.0 Aim of the Micro-Project: The aim of the calculator project in Python
is to create a simple yet functional tool that allows users to perform basic
arithmetic operations such as addition, subtraction, multiplication, and division.
It serves as an educational exercise to practice programming fundamentals and
develop problem-solving skills.
4.0
Actual Resources used : Window operating system ,internet, Python 3.7

5.0 Skill Developed/learning out of this Micro-Project:

1. Teamwork
2. Communication skills
3. Able to create a calculator in python program.

7.0 CONCLUSION:-

13 | M I T P o l y t e c h n i c P u n e
To create a simple calculator using classes and objects in python

In conclusion, the calculator project in Python utilizing classes and objects


serves as an effective demonstration of object-oriented programming principles
and basic software development concepts. Through this project, developers
gain insights into the following:

Modular Design: Using classes and objects enables a modular design,


promoting code organization, reusability, and maintainability. Encapsulation
and Abstraction: The project demonstrates the principles of encapsulation and
abstraction by encapsulating data and behaviour within classes, abstracting
away implementation details, and providing a clear interface for users.
Flexibility and Extensibility: The project's structure allows for easy extension
and modification. Additional functionality and operations can be added by
simply creating new methods or subclasses without affecting existing code.
Enhanced Code Readability: By organizing code into classes and methods, the
project enhances code readability, making it easier to understand, debug, and
maintain. Application of Object-Oriented Concepts: Developers apply object-
oriented concepts such as inheritance, polymorphism, and composition to
model real-world entities and relationships effectively.

Micro-project evaluation sheet


14 | M I T P o l y t e c h n i c P u n e
To create a simple calculator using classes and objects in python

Rol Student Enroll Process Product Total


l Name m ent Assessme Assessment Mark
no. number nt s
(10)
Part A- Project Part Individual
Project Methodol B-Project Presentation
Propaso ogy report/ /Viva
al (2) working (4)
(2) model
(2)

Comments about team work/leadership/inter-personal


communication (if any):
________________________________________________________________
____________________________________________________

Any Other Comment:


________________________________________________________________
____________________________________________________

Name and designation of the faculty member:


Prof. (Micro-Project Guide)

Signature: ____________________

Logbook of the Student (Weekly Work Report)


Academic Year: 2023-2024
15 | M I T P o l y t e c h n i c P u n e
To create a simple calculator using classes and objects in python

Name of Students :

Title of the Project:- To create a simple calculator using classes and


objects in python.

Course : CO6I Course-code:22616 semester:6I

(Name & Signature of faculty)


Prof.

16 | M I T P o l y t e c h n i c P u n e

You might also like