Friday, January 8, 2021

Python code for simple operational calculator

First Method:


n1=float(input("Enter number1:"))

n2=float(input("Enter number2:"))

sign=input("Enter sign:")

if sign=='+':

    print("Answer=",n1+n2)

elif sign=='-':

    print("Answer=",n1-n2)

elif sign=='*':

    print("Answer=",n1*n2)

elif sign=='/':

    print("Answer=",n1/n2)

else:

    print("Invalid sign")


Second Method: 


n1=float(input("Enter number1:"))

n2=float(input("Enter number2:"))

sign=input("Enter sign:")

if sign=='+':

    n=n1+n2

elif sign=='-':

    n=n1-n2

elif sign=='*':

    n=n1*n2

elif sign=='/':

    n=n1/n2

else:

    print("Invalid sign")

print("Answer=",n)

No comments:

Post a Comment

How to Fight Overthinking or Negative Thoughts?

How to Combat Overthinking or Negative Thoughts? 1. Don’t Fight Your Thoughts Trying to suppress or control negative thoughts often backfire...