我是python的新手,我的计算器代码不起作用,而不是在c或c ++中运行

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:意外缩进

请有人帮我

评论
  • ofbgg
    ofbgg 回复

    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 the indentation error.

    删除空间。它将解决您的问题。

    Tips: If you're using Pycharm see in the toolbar that there's an option called Code. Click it and you'll find an option Reformat Code. That will fix the formatting issue as configured in the IDE.

  • ousman
    ousman 回复

    只需缩进输入行,就可以了。 在运行程序之前请注意弹出的错误,这样的事情将不会再次发生。

  • jvitae
    jvitae 回复

    第36行上不应有空格。 Python对缩进很敏感,因此空格会导致错误。

    更改

     n = input("Enter the option ")
    

    n = input("Enter the option ")
    

    然后再试一次。