Reputation: 3
I writing this this code for a Stepik course. Description of the task says:
Write a simple calculator that reads three lines from user input: the first number, the second number, and the operation, and then applies the operation to the entered numbers ("first number" "operation" second number") and displays the result.
Supported operations: +, -, /, *, mod, pow, div, where mod is taking the remainder of the division, pow — exponentiation, div — integer division.
If division is performed and the second number is 0, output the string "Division by 0!".
Please note that the input program comes real numbers.
I tried near 10 different times and the program shows me the same error.
One of my tries:
a,b,c = float(input()), float(input()), str(input())
if c == '+':
print(a+b)
elif c == '-':
print(a-b)
elif c == '*':
print(a * b)
elif c == '**':
print(a**b)
elif c == 'mod':
if b == 0:
print('Деление на 0!') # Division by 0!
else:
print(a%b)
elif c == '/':
if b == 0:
print('Деление на 0!') # Division by 0!
else:
print(a/b)
elif c == '//':
if b == 0:
print('Деление на 0!') # Division by 0!
else:
print(a//b)
In my IDLE (PyCharm) all works good, the program outputs "Division by 0!" where it needs. But when I check my code on browser it outputs:
Failed test #5. Cannot check answer. Perhaps output format is wrong.
Upvotes: 0
Views: 114
Reputation: 361555
You implemented **
and //
but the spec calls for pow
and div
.
Upvotes: 5