我看不出我的代码有什么问题。我不会写一个简单的计算器
I can't see what's wrong with my code. I can't write a simple calculator
我为 Stepik 课程编写此代码。任务描述说:
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.
我尝试了将近 10 次,程序显示相同的错误。
我的一个尝试:
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)
在我的 IDLE (PyCharm) 中一切正常,程序在需要的地方输出 "Division by 0!"。但是当我在浏览器上检查我的代码时它输出:
Failed test #5. Cannot check answer. Perhaps output format is wrong.
您实现了 **
和 //
,但规范要求 pow
和 div
。
我为 Stepik 课程编写此代码。任务描述说:
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.
我尝试了将近 10 次,程序显示相同的错误。
我的一个尝试:
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)
在我的 IDLE (PyCharm) 中一切正常,程序在需要的地方输出 "Division by 0!"。但是当我在浏览器上检查我的代码时它输出:
Failed test #5. Cannot check answer. Perhaps output format is wrong.
您实现了 **
和 //
,但规范要求 pow
和 div
。