calculator in python project code example

Example 1: how to make a complex calculator in python

Just Ctrl-C and Ctrl-V

num1 = float(input("Enter first number... "))
op = input("Enter an Operation... ")
num2 = float(input("Enter second number... "))
if op == ("+"):
    print(num1+num2)
elif op == ("-"):
    print(num1-num2)
elif op == ("*"):
    print(num1 * num2)
elif op == ("/"):
    print(num1/num2)

Example 2: 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)

Example 3: Calculator in python

num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
# And then print out the result

Example 4: non-words in python

import re

regex = re.compile('[^a-zA-Z]')
#First parameter is the replacement, second parameter is your input string
regex.sub('', 'ab3d*E')
#Out: 'abdE'