calculator function in python code example
Example 1: calculator python tutorial
while True:
Cal = input("")
print(eval(Cal))
Example 2: calculator with python
A = int(input("Enter your first number: "))
operator = input("Which operation would you like to perform? (+, -, /, *, //, **): ");
B = int(input("Enter your second number: "))
if operator == "+":
ans = A + B
print(str(ans))
elif operator == "-":
ans = A - B
print(str(ans))
elif operator == "/":
ans = A / B
print(str(ans))
elif operator == "*":
ans = A * B
print(str(ans))
elif operator == "//":
ans = A // B
print(str(ans))
elif operator == "**":
ans = A ** B
print(str(ans))
else:
print("wrong operator!")