Python Examples
Find out few Python Examples:-
Simple calculator in Python
num1 = int(input("Enter first number:"))
num2 = int(input("Enter second number:"))
action = str(input("Choose action: add(a), sub(s), mult(m),div(d)->"))
print("The result is :", end="")
if action == "a":
print(num1+num2)
elif action == "s":
print(num1-num2)
elif action == "m":
print(num1*num2)
else:
print(num1/num2)
Another calculator
# Program make a simple 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("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
# take input from the user
choice = input("Enter choice(1/2/3/4): ")
No comments