Answer to Question #202519 in Python for Angelie Suarez

Question #202519

MODULE 10:

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-06-04T06:02:39-0400
a, b = None, None
res=0
while True:
    if a is None:
        a = float(input("what's the first number?:"))
    # enter an operator
    print('+', '-', '*', '/', '%', 'e', sep='\n')
    op = input("pick an operation:")
    if b is None:
        b = float(input("what's the number?:"))
    if op == '+':
        res = a + b
    elif op == '-':
        res = a - b
    elif op == '*':
        res = a * b
    elif op == '/':
        res = a / b
    elif op == '%':
        res = a % b
    elif op == 'e':
        res = a ** b
    if res is not None:
        print(f"{a} {op} {b} = {res}")
    op = input("type 'y' to continue calculating with 3.0, or type 'n' to start a new calculation:")
    if op == 'y':
        a, b, res = res, None, None
    else:
        a, b, res = None, None, None

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