Answer to Question #201187 in Python for Angelie Suarez

Question #201187

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: 

  • MODULUS DIVISION

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:


  • EXPONENT

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:



1
Expert's answer
2021-05-31T09:15:48-0400
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: ")
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS