Go ahead and try to write the code in this module. If you accomplished it and run without an issue, add
another feature of our calculator. Try to add the following:
SAMPLE OUTPUT:
what's the first number?:15
+
-
*
/
%
e
pick an operation:%
what's the number?: 4
15.0% 4.0=3.0
type 'y' to continue calculating with 3.0, or type 'n' to start a new calculation:
SAMPLE OUTPUT:
what's the first number?:5
+
-
*
/
%
e
pick an operation:e
what's the number?: 3
5.0% 3.0= 125.0
type 'y' to continue calculating with 125.0, or type 'n' to start a new calculation:
answer="n"
result=0
while(True):
firstNumber=result
if (answer=="n"):
firstNumber=int(input("what's the first number?: "))
print("+\n-\n*\n/\n%\ne")
operation=input("pick an operation: ")
secondNumber=int(input("what's the number? "))
if(operation=="+"):
result=firstNumber+secondNumber
elif(operation=="-"):
result=firstNumber-secondNumber
elif(operation=="*"):
result=firstNumber*secondNumber
elif(operation=="/"):
result=firstNumber/secondNumber
elif(operation=="%"):
result=firstNumber%secondNumber
elif(operation=="e"):
result=pow(firstNumber,secondNumber)
else:
print("Wrong operation")
answer="x"
break
if answer!="x":
print(f"{firstNumber} {operation} {secondNumber} = {result}")
answer=input("type 'y' to continue calculating with 3.0, or type 'n' to start a new calculation: ")
Comments
Leave a comment