How to Make Calculator in Python?
Input
#simple caloculatar program
import sys
import math
x=int(input("enter first number:"))
print('''add(+)
subtract(-)
multiply(*)
devide(/)
square(s)
square root(R)''')
choice=input("choice opreations....:(+,-,*,/,s,R)=")
while choice=='s':
print(x**2)
sys.exit()
while choice=='R':
print(math.sqrt(x))
sys.exit()
y=int(input("enter second number:"))
if choice=='+':
print(x+y)
elif choice=='-':
print(x-y)
elif choice=='*':
print(x*y)
elif choice=='/':
print(x/y)
else:
print("invalid opreation")
Output
enter first number:5
add(+)
subtract(-)
multiply(*)
devide(/)
square(s)
square root(R)
choice opreations....:(+,-,*,/,s,R)=s
subtract(-)
multiply(*)
devide(/)
square(s)
square root(R)
choice opreations....:(+,-,*,/,s,R)=s
25
👍👍👍
ReplyDelete