简体   繁体   中英

I can't see what's wrong with my code. I can't write a simple calculator

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.

您实现了**//但规范要求使用powdiv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM