0% found this document useful (0 votes)
25 views2 pages

# Calculator 2

Uploaded by

drerginyildiz278
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)
25 views2 pages

# Calculator 2

Uploaded by

drerginyildiz278
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/ 2

# Calculator 2

import math

# This function adds two numbers


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

# This function subtracts two numbers


def subtract(x, y):
return x - y

# This function multiplies two numbers


def multiply(x, y):
return x * y

# This function divides two numbers


def divide(x, y):
return x / y

def ex(x, y):


return x ** y

def eb(x, y):


return math.gcd(x, y)

def ek(x, y):


return (x * y) // (math.gcd(x, y))

def re(x, y):


return x % y

def fl(x, y):


return x // y

def sup(x, y):


return ((x + (y * 2)) // 7) % 3

print("Select operation.")
print("1.Addition")
print("2.Subtraction")
print("3.Multiplication")
print("4.Divison")
print("5.Exponent")
print("6.Greatest Common Divisor")
print("7.Smallest Common Multiple")
print("8.Reminder of Divison")
print("9.Full Divison")
print("0.Suprise")

while True:
# take input from the user
choice = input("Enter choice(1/2/3/4/5/6/7/8/9/0) ->")

# check if choice is one of the four options


if choice in ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'):
try:
num1 = int(input("Enter first number -> "))
num2 = int(input("Enter second number ->"))
except ValueError:
print("Invalid input. Please enter a number.")
continue

if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2':


print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3':


print(num1, "*", num2, "=", multiply(num1, num2))

elif choice == '4':


print(num1, "/", num2, "=", divide(num1, num2))

elif choice == '5':


print(num1, "^", num2, "=", ex(num1, num2))

elif choice == '6':


print(num1, ",", num2, "=", eb(num1, num2))

elif choice == '7':


print(num1, ",", num2, "=", ek(num1, num2))

elif choice == '8':


print(num1, " mod ", num2, "=", re(num1, num2))

elif choice == '9':


print(num1, "/", num2, "=", fl(num1, num2))

elif choice == '0':


print(num1, "+", num2, "and some junk you have to find", "=", sup(num1,
num2))

# to see
# to see
next_calculation = input("Let's do next calculation? (yes/no) -> ")
if next_calculation == "no":
break
else:
print("Invalid Input")

You might also like