Python Calculator
from whiteCalculator import Calculator
c = Calculator()
print(c.run("1+8(5^2)"))
# Output: 201
print(c.run("9Ans"))
# Output: 1809
Python Calculator
from whiteCalculator import Calculator
c = Calculator()
print(c.run("1+8(5^2)"))
# Output: 201
print(c.run("9Ans"))
# Output: 1809
python calculator
num_one = int(input("Enter 1st number: "))
op = input("Enter operator: ")
num_two = int(input("Enter 2nd number: "))
if op == "+":
print(num_one + num_two)
elif op == "-":
print(num_one - num_two)
elif op == "*" or op == "x":
print(num_one * num_two)
elif op == "/":
print(num_one / num_two)
python calculator
print("Enter Your Choice 1(Add)/2(Sub)/3(Divide)/4(Multiply)")
num = int(input())
if num == 1:
print("Enter Number 1 : ")
add1 = int(input())
print("Enter Number 2 : ")
add2 = int(input())
sum = add1 + add2
print("The Sum Is ", sum)
elif num == 2:
print("Enter Number 1 : ")
sub1 = int(input())
print("Enter Number 2 : ")
sub2 = int(input())
difference = sub1 - sub2
print("The Difference Is ", difference)
elif num == 3:
print("Enter Number 1 : ")
div1 = float(input())
print("Enter Number 2 : ")
div2 = float(input())
division = div1 / div2
print("The Division Is ", division)
elif num == 4:
print("Enter Number 1 : ")
mul1 = int(input())
print("Enter Number 2 : ")
mul2 = int(input())
multiply = mul1 * mul2
print("The Difference Is ", multiply)
else:
print("enter a valid Number")
python calculator
# define the function
def calculate():
print('Please choose your operator adding(+) subtracting(-) multiplying(*) didviding(/) for power(**) for module(%)')
number_1 = int(input("Enter your first digit: "))
operation = input("Enter your operator: ")
number_2 = int(input("Enter your first digit: "))
# adding
if operation == '+':
print('{} + {} = '.format(number_1, number_2))
print(number_1 + number_2)
print("You were adding.\n")
print("How do I know that I'm a smart progammer ;)\n")
# subtracting
elif operation == '-':
print('{} - {} = '.format(number_1, number_2))
print(number_1 - number_2)
print("You were subtracting.\n")
print("How do I know that I'm a smart progammer ;)\n")
# mulitplaying
elif operation == '*':
print('{} * {} = '.format(number_1, number_2))
print(number_1 * number_2)
print("You were mulitplaying.")
print("How do I know that I'm a smart progammer ;)\n")
# dividing
elif operation == '/':
print('{} / {} = '.format(number_1, number_2))
print(number_1 / number_2)
print("You were dividing.\n")
print("How do I know that I'm a smart progammer ;)\n")
# for power
elif operation == '**':
print('{} ** {} = '.format(number_1, number_2))
print(number_1 ** number_2)
print("You were using for power.\n")
print("How do I know that I'm a smart progammer ;)\n")
# module
elif operation == '%':
print('{} % {} = '.format(number_1, number_2))
print(number_1 % number_2)
print("You were using module.\n")
print("How do I know that I'm a smart progammer ;)\n")
# if they get a error
else:
print("Your number you have typed is invalid, please restart your program!")
# add again() here as a function outside the calculate()
again()
def again():
cal_again = input("Do you want to calculate again? Y = yes or N = no: ")
# Taking user input
if cal_again.upper() == 'Y':
calculate()
elif cal_again.upper() == 'N':
print('Leave kid ;-;')
else:
again()
def welcome():
print("Welcome to my calculator made by Pepa pig lol made in python :D")
# use calculate() for the function
welcome()
calculate()
python calculator
import time
def cal():
def add(x, y):
print(x + y)
def sub(x, y):
print(x - y)
def mul(x, y):
print(x * y)
def div(x, y):
print(x // y)
while True:
print('Adding?(+) Subtracting?(-) Multiplying?(*) Dividing?(/)')
answer = input('')
if answer == "+":
try:
x = float(input('First number! '))
y = float(input('Second Number! '))
except Exception as e:
print(f'Error: {e}')
time.sleep(5)
return
add(x, y)
elif answer == "-":
try:
x = float(input('First number! '))
y = float(input('Second Number! '))
except Exception as e:
print(f'Error: {e}')
time.sleep(5)
return
sub(x, y)
elif answer == "*":
try:
x = float(input('First number! '))
y = float(input('Second Number! '))
except Exception as e:
print(f'Error: {e}')
time.sleep(5)
return
mul(x, y)
elif answer == "/":
try:
x = float(input('First number! '))
y = float(input('Second Number! '))
except Exception as e:
print(f'Error: {e}')
time.sleep(5)
return
div(x, y)
else:
print('Error. Enter a valid input!')
cal()
python calculator
print('Calculator')
input_1 = input('First Number? ')
input_2 = input('Second Number? ')
try:
print(f'{input_1} + {input_2} is {float(input_1) + float(input_2)}')
print(f'{input_1} - {input_2} is {float(input_1) - float(input_2)}')
print(f'{input_1} X {input_2} is {float(input_1) * float(input_2)}')
print(f'{input_1} / {input_2} is {float(input_1) // float(input_2)}')
except Exception as e:
print(f'ERROR: {e}')
python calculator
#Simple faulty calculator
# 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
print("Select operation.")
print("Add = +")
print("Subtract = -")
print("Multiply = *")
print("Divide = /")
while True:
# Take input from the user
choice = input("Enter choice(+ or - or * or /): ")
# Check if choice is one of the four options
if choice in ('+', '-', '*', '/'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '+':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '-':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '*':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '/':
print(num1, "/", num2, "=", divide(num1, num2))
break
else:
print("Invalid Input")
python calculator
#Store number variables for the two numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
#the sum of the two numbers variable
sum = float(num1) + float(num2)
sum2 = float(num1) - float(num2)
sum3 = float(num1) * float(num2)
sum4 = float(num1) / float(num2)
#what operator to use
choice = input('Enter an operator, + = addition, - = subtraction, * = multiplication and / = division: ')
#different sums based on the operators
if choice == '+':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
if choice == '-':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum2))
if choice == '*':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum3))
if choice == '/':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum4))
python calculator
import math
def SquareRoot (x):
return math.sqrt(x)
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
def hcf(a,b):
H=a if a<b else b
while H>=1:
if a%H==0 and b%H==0:
return H
H-=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):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.lcm")
print("6.SquareRoot")
print("7.hcf")
while True:
choice = input("Enter choice(1/2/3/4/5/6/7): ")
if choice in ('1', '2', '3', '4','5','7'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
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("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))
elif choice == '7':
print("The H.C.F of", num1,"and", num2,"is", hcf(num1, num2))
next_calculation = input("Do you want to do another calculation (yes/no): " )
if next_calculation == "no":
break
elif choice in ('6'):
num0 = float(input("Enter a number: "))
if choice == '6':
print("The SquareRoot of ",num0,"is",SquareRoot(num0))
else:
print("Invalid Input")
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us