0% found this document useful (0 votes)
2 views16 pages

CS Project

The document presents a computer science project on a Basic Python Calculator created by students from Kendriya Vidyalaya Sector-5, detailing its features, coding steps, and error handling mechanisms. It includes a certificate of completion, acknowledgments, an overview of the project, coding explanations, and outputs. Additionally, it provides background information on Python programming and a bibliography of sources used.

Uploaded by

revantop12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

CS Project

The document presents a computer science project on a Basic Python Calculator created by students from Kendriya Vidyalaya Sector-5, detailing its features, coding steps, and error handling mechanisms. It includes a certificate of completion, acknowledgments, an overview of the project, coding explanations, and outputs. Additionally, it provides background information on Python programming and a bibliography of sources used.

Uploaded by

revantop12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1 | Page

KENDRIYA VIDYALAYA SECTOR-5


DWARKA, NEW DELHI (110075)

COMPUTER
SCIENCE PROJECT BY
REVANT RANJAN, ANISHEK JAIN, PODEM
GAGAN CHANDRA
XI A
BASIC PYTHON CALCULATOR
2 | Page

INDEX
PAGES CONTENT
3-4 CERTIFICATE,ACKNOWLEDGEMENT
5 OVERVIEW OF THE PROJECT
6-9 STEPS IN CREATING THE PROGRAM
10-12 EXPLANATION OF THE CODING
13-14 VARIOUS OUTPUTS OF THE
PROGRAM
15 ABOUT PYTHON
16 BIBLIOGRAPHY
3 | Page

CERTIFICATE

This is to certify that MASTER REVANT


RANJAN ,MASTER ANISHEK JAIN,MASTER
PODEM GAGAN CHANDRA of class XI A
with CLASS ROLL NO. 32, 9 and 30
respectively of SESSION 2024-25 have
satisfactorily completed computer science
project on ‘BASIC PYTHON CALCULATOR’ as
per the CBSE guidance under Mr BHAGAT
SINGH RAJAWAT of KENDRIYA VIDYALAYA
SECTOR-5 DWARKA NEW DELHI.

SIGNATURE SIGNATURE SIGNATURE


SUBJECT EXTERNAL PRINCIPAL
TEACHER EXAMINER
4 | Page

ACKNOWLEDGEMENT
The success and final outcome of this project was
the result of contributions by many people.Firstly,
we would like to thank to our INFORMATICS
PRACTICSES TEACHER MR. BHAGAT SINGH, who
initially gave us the opportunity to work on this
project and later helped us complete the project
on time.
We thank our honourable PRINCIPAL SIR
MR.KARMVEER SINGH for his constant support
and motivation which helped us complete our
project sincerely.
It would not be fair if we don’t thank our parents
and our classmates for their help and determined
support which helped our personal motivation
and ambition towards the completion of this
project.
PLACE: NAME:
5 | Page

OVERVIEW OF THE PROJECT


The Basic Calculator is a simple yet effective
program designed to perform fundamental
arithmetic operations. Users can perform
addition, subtraction, multiplication, and
division by inputting two numbers and
selecting an operation. The calculator ensures
robust error handling, including managing
division by zero and invalid inputs, making it
user-friendly and reliable.

SOME FEATURES –
• Basic Arithmetic Operations: Addition, Subtraction,
Multiplication, and Division.
• Error Handling: Prevents division by zero and invalid
inputs.
• User-Friendly Interface: Interactive and intuitive
console-based selection system.
• Continuous Execution: Allows multiple calculations until
the user decides to exit.
• Lightweight & Efficient: Simple logic with minimal
resource consumption.
6 | Page

STEPS IN CREATING THE PROGRAM


1. Define Functions for Arithmetic Operations:
o Create separate functions for addition,
subtraction, multiplication, and division.
o Ensure the division function handles
division by zero.

2. User Input and Operation Selection:


o Prompt the user to input two numbers and
select an operation.
o Use conditional statements to determine
which operation to perform.

3. Error Handling:
o Use try-except blocks to handle invalid
inputs (e.g., non-numeric values).
o Check for division by zero in the division
function.
4. Continuous Use:
o Use a loop to allow the user to perform
multiple calculations.
o Provide an option to exit the calculator.
7 | Page

THE CODINGS FOR THE PYTHON PROGRAM ARE:


# Basic Calculator Program

# Define functions for arithmetic operations


def add(x, y):
return x + y

def subtract(x, y):


return x - y

def multiply(x, y):


return x * y

def divide(x, y):


if y == 0:
raise ValueError("Error: Division by zero is not allowed.")
return x / y

# Main calculator function


def calculator():
while True:
print("\n--- Basic Calculator ---")
print("Operations:")
8 | Page

print("1. Addition (+)")


print("2. Subtraction (-)")
print("3. Multiplication (*)")
print("4. Division (/)")
print("5. Exit")

# Get user input for operation


try:
choice = input("Select an operation (1/2/3/4) or 5 to exit: ")
if choice == '5':
print("Exiting the calculator. Goodbye!")
break

# Get user input for numbers


num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

# Perform the selected operation


if choice == '1':
result = add(num1, num2)
print(f"Result: {num1} + {num2} = {result}")
elif choice == '2':
result = subtract(num1, num2)
print(f"Result: {num1} - {num2} = {result}")
9 | Page

elif choice == '3':


result = multiply(num1, num2)
print(f"Result: {num1} * {num2} = {result}")
elif choice == '4':
try:
result = divide(num1, num2)
print(f"Result: {num1} / {num2} = {result}")
except ValueError as e:
print(e)
else:
print("Invalid choice. Please select a valid operation.")

except ValueError:
print("Error: Invalid input. Please enter numeric values.")

# Run the calculator


calculator()

5. Display Results:
o Print the result of the calculation.
o Display appropriate error messages if
invalid inputs or operations are
encountered.
10 | Page

EXPLANATION OF THE CODINGS

1. Functions for Operations:


o Four functions (add, subtract, multiply, divide)
are defined to perform the respective arithmetic
operations.
o The divide function includes a check for division
by zero and raises a ValueError if encountered.

2. User Input and Operation Selection:


o The user is prompted to select an operation by
entering a number (1-4) or exit by entering 5.
o The program uses if-elif-else statements to
determine which operation to perform based on
the user's choice.

3. Error Handling:
o A try-except block is used to handle invalid
inputs (e.g., non-numeric values).
o The divide function includes a check for division
by zero and raises an error if detected.
11 | Page

4. Continuous Use with a Loop:


o The calculator runs inside a while loop, allowing
the user to perform multiple calculations without
restarting the program.
o After each calculation, the user is prompted to
select another operation or exit the program by
choosing option 5.

5. Displaying Results and Error Messages:


• The result of each calculation is displayed in a
clear and readable format, showing the operation
performed and the result.
• If an error occurs (e.g., invalid input or division
by zero), a descriptive error message is
displayed to guide the user.

Example Workflow:
1. User selects addition:
o Input: 1 (for addition), 10 (first
number), 5 (second number).
o Output: Result: 10.0 + 5.0 = 15.0.
2. User selects division by zero:
o Input: 4 (for division), 10 (first number), 0 (second
number).
o Output: Error: Division by zero is not allowed.
3. User enters invalid input:
o Input: 2 (for subtraction), ten (first number).
12 | Page

o Output: Error: Invalid input. Please enter numeric


values.
4. User exits the program:
o Input: 5 (to exit).
o Output: Exiting the calculator. Goodbye!
13 | Page

OUTPUTS OF THE PROGRAM

Example 1: Addition

Example 2: Division by Zero


14 | Page

Example 3: Invalid Input

Example 4: Exit
15 | Page

ABOUT PYTHON
Python is an interpreted, high-level and general-purpose programming
language. Python's design philosophy emphasizes code readability with its
notable use of significant indentation. Its language constructs and object-
oriented approach aim to help programmers write clear, logical code for
small and large-scale projects.[29]
Python is dynamically-typed and garbage-collected. It supports
multiple programming paradigms,
including structured (particularly, procedural), object-
oriented and functional programming. Python is often described as a
"batteries included" language due to its comprehensive standard library.[30]
Python was created in the late 1980s, and first released in 1991, by Guido
van Rossum as a successor to the ABC programming language. Python 2.0,
released in 2000, introduced new features, such as list comprehensions,
and a garbage collection system with reference counting, and was
discontinued with version 2.7 in 2020.[31] Python 3.0, released in 2008, was
a major revision of the language that is not completely backward-
compatible and much Python 2 code does not run unmodified on Python 3.
With Python 2's end-of-life (and pip having dropped support in 2021[32]),
only Python 3.6.x[33] and later are supported, with older versions still
supporting e.g. Windows 7 (and old installers not restricted to 64-bit
Windows).
Python interpreters are supported for mainstream operating systems and
available for a few more (and in the past supported many more). A global
community of programmers develops and maintains CPython, a free and
open-source[34] reference implementation. A non-profit organization,
the Python Software Foundation, manages and directs resources for Python
and CPython development.
As of February 2021, Python ranks third in TIOBE’s index of most popular
programming languages, behind C and Java,[35] having previously gained
second place and their award for the most popularity gain for 2020.
16 | Page

Bibliography
● https://en.wikipedia.org
● https://www.google.co.in
● https://WWW.W3SCHOOLS.COM
● CLASS 11 COMPUTER SCIENCE by sumita
arora
● https://WWW.TUTORIALSPOINT.COM

You might also like