def add(x, y):
c = x + y
print(c)
def sub(x, y):
c = x - y
print(c)
def multi(x, y):
c = x * y
print(c)
def div(x, y):
c = x / y
print(c)
def test(m):
if m == '1':
add(a, b)
elif m == '2':
sub(a, b)
elif m == '3':
multi(a, b)
elif m == '4':
div(a, b)
else:
print("Enter above menu")
print("1 add\n2 sub\n3 multi\n4 div\n")
n = input("Enter the option ")
a, b = input("Enter the numbers ").split()
test(n)
我得到的错误是 文件“ C:/Users/HP/PycharmProjects/CALCULATOR/main.py”,第36行 n =输入(“输入选项”) ^ IndentationError:意外缩进
请有人帮我
It's an indentation problem. There's a space in
line 36
. Therefore, when the interpreter is translating the code, it's seeing an extra space. That's why it's giving theindentation error
.删除空间。它将解决您的问题。
Tips: If you're using
Pycharm
see in the toolbar that there's an option calledCode
. Click it and you'll find an optionReformat Code
. That will fix the formatting issue as configured in the IDE.只需缩进输入行,就可以了。 在运行程序之前请注意弹出的错误,这样的事情将不会再次发生。
第36行上不应有空格。 Python对缩进很敏感,因此空格会导致错误。
更改
至
然后再试一次。