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:
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:
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
Comments
Leave a comment