[go: up one dir, main page]

0% found this document useful (0 votes)
11 views1 page

Advance Calculator

The document outlines a simple calculator program that performs basic arithmetic operations: addition, subtraction, multiplication, and division. It includes user prompts for selecting operations and inputting numbers, along with error handling for division by zero. The program runs in a loop until the user chooses to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Advance Calculator

The document outlines a simple calculator program that performs basic arithmetic operations: addition, subtraction, multiplication, and division. It includes user prompts for selecting operations and inputting numbers, along with error handling for division by zero. The program runs in a loop until the user chooses to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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:
return "Math Error, cannot divide by zero."
return x / y

# Introduction message
print("WELCOME TO THE CALCULATOR OF NURAZ!")
print("YOU ARE REQUESTED TO NOT LEAVE!")

while True:
print("\n1. Add\n2. Subtract\n3. Multiply\n4. Divide\n5. Exit")
choice = input("Choose an operation (1/2/3/4/5): ")

if choice == '5':
print("AYE AYE SIR! SELF DESTRUCTING INITIALIZED")
break

if choice == '1':
print("Addition Operation Selected")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(f"Result: {add(num1, num2)}")

elif choice == '2':


print("Subtraction Operation Selected")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(f"Difference: {subtract(num1, num2)}")

elif choice == '3':


print("Multiplication Operation Selected")
num1 = float(input("Enter Multiplicand: "))
num2 = float(input("Enter Multiplier: "))
print(f"Product: {multiply(num1, num2)}")

elif choice == '4':


print("Division Operation Selected")
num1 = float(input("Enter Dividend: "))
num2 = float(input("Enter Divisor: "))
print(f"Quotient: {divide(num1, num2)}")

else:
print("Invalid choice. Please try again.")

# Ask if the user wants to continue or exit


check = input("Exit Calculator (yes/no)?: ")
if check.lower() == 'yes':
print("EVISCERATING CALCULATOR!")
break

You might also like