Simple calculator using if-else statement in Python programming. In this tutorials you will learn how to write a simple calculator which allows you to add, subtract, and multiply integers values.
num = int(input("Enter value from 1 to 5: "))
if num >= 1 and num <= 5: #if 'num' value Less then or equal to 1 And
#gretter then OR equal to 5 then
print("Welcome!") #print this.
else: #if not then
print("Invalid Entry!") #print this.
num = int(input("Enter value from 1 to 4: "))
if num == 1 or num == 2 or num == 3 or num == 4: #if 'num' value equal to 1
#OR equal to 2 OR equal to 3 OR equal to 4 then
print("Welcome!") #print this.
else: #if not then
print("Invalid Entry!") #print this.
a = int(input("Enter First Integer: "))
op = input("Enter Operator: ")
b = int(input("Enter 2nd Integer: "))
if op == '+': #if 'op' value equal to '+' then
print("Addition is: ", a + b) #print this.
elif op == '-': #if 'op' value equal to '-' then
print("Subtraction is: ", a - b) #print this.
elif op == '*': #if 'op' value equal to '*' then
print("Multiplication is: ", a * b) #print this.
else: #if not in above then
print("Invalid Operator") #print this.