COMPUTER SCIENCE PRACTICAL
FILE
“The computer was born to solve problems that did not exist before.”
SUBMITTED BY: - SUBMITTED TO: -
AKASH CHAUHAN SHURBI PATHAK MA’AM
XIth A (17)
ACKNOWLEDGEMENT
I would like to express my profound gratitude to
Mrs. Mamta of Kendriya
Vidyalaya Sadiq Nagar for their contributions to
the completion of my project.
I would like to express my special thanks to our
mentor Mrs. Shurbi Pathak Ma’am for her time and
efforts she provided throughout the year. Your
useful advice and suggestions were really helpful
to me during the project’s completion. In this
aspect, I am eternally grateful to you.
I would like to acknowledge that this project was
completed entirely by me and not by someone
else.
CALCULATOR
PROGRAM: -
# Function for addition
def add (x, y):
return x + y
# Function for subtraction
def subtract (x, y):
return x - y
# Function for multiplication
def multiply (x, y):
return x * y
# Function for division
def divide (x, y):
if y! = 0:
return x / y
else:
return "Error! Division by zero."
# Main function to control the flow of the program
def calculator ():
print ("Select operation:")
print ("1. Add")
print ("2. Subtract")
print ("3. Multiply")
print ("4. Divide")
choice = input ("Enter choice (1/2/3/4): ")
# Check if the user input is valid
if choice in ['1', '2', '3', '4']:
num1 = float (input ("Enter first number: "))
num2 = float (input ("Enter second number: "))
if choice == '1':
print(f"{num1} + {num2} = {add (num1, num2)}")
elif choice == '2':
print(f"{num1} - {num2} = {subtract (num1,
num2)}")
elif choice == '3':
print(f"{num1} * {num2} = {multiply (num1,
num2)}")
elif choice == '4':
print(f"{num1} / {num2} = {divide (num1, num2)}")
else:
print ("Invalid input! Please select a valid
operation.")
# calculator function to start Call the
calculator ()
OUTPUT: -
Select operation:
1. Add
2. Subtract
3. Multiply
4. Divide
Enter choice (1/2/3/4): 1
Enter first number: 10
Enter second number: 5
10.0 + 5.0 = 15.0
SOURCES: -
: - CHAT GPT
: - PRETTI ARORA