这个缩进错误是什么?

时间:2017-04-19 14:57:17

标签: python

print("Welcome to calculator.py")
print ("your options are :")
print ("")
print ("1) Addition")
print ("2)Subtraction")
print ("3) Multiplication")
print ("4)Division")
print ("Choose your option")


#this adds 2 numbers given

def add (a,b):
print(a, "+" ,b, "=" ,a+b)

#this subtracts 2 numbers given
def sub (a,b):
print(a, "-" ,b, "=" ,b-a)

#this multiplies 2 numbers given
def mul(a,b):
print(a, "*" ,b, "=" ,a*b)

#this divides 2 numbers given
def div(a,b):
def div(a, "/" ,b, "=" ,a/b)

#NOW THE PROGRAM REALLY STARTS ,AS CODE IS RUN
loop = 1
choice = 0
while loop == 1:
choice = menu()

if choice == 1:
    add (input("Add this: "),input ("to this: "))

        elif choice == 2:
    sub(input("Subtract this: "),input ("from this: "))


    elif choice == 3:
    mul (input("Multiply this: "),input ("by this: "))

    elif choice == 4:
    div(input("Divide this: "),input ("by this: "))

    elif choice ==5:
        loop = 0

        print ("Thank you for using calculator.py")

这是我的代码,错误是:     打印(a," +",b," =",a + b)         ^ IndentationError:预期缩进块

流程以退出代码1结束 还有很多人可以帮我找到所有的错误??? 任何人都可以帮助我???

3 个答案:

答案 0 :(得分:0)

在python中,块由缩进定义。定义函数后,您应该有一个缩进(制表符)。

答案 1 :(得分:0)

几乎所有的缩进都是错误的,而不仅仅是那个地方:

print("Welcome to calculator.py")
print("your options are :")
print("")
print("1) Addition")
print("2)Subtraction")
print("3) Multiplication")
print("4)Division")
print("Choose your option")


#this adds 2 numbers given

def add(a,b):
    print(a, "+", b, "=" , a+b)

#this subtracts 2 numbers given
def sub(a,b):
    print(a, "-", b, "=" , b-a)

#this multiplies 2 numbers given
def mul(a,b):
    print(a, "*", b, "=" , a*b)

#this divides 2 numbers given
def div(a,b):
    print(a, "/", b, "=", a/b)

#NOW THE PROGRAM REALLY STARTS, AS CODE IS RUN
loop = 1
choice = 0
while loop == 1:
    choice = menu()

    if choice == 1:
        add(input("Add this: "), input("to this: "))
    elif choice == 2:
        sub(input("Subtract this: "), input("from this: "))
    elif choice == 3:
        mul(input("Multiply this: "), input("by this: "))
    elif choice == 4:
        div(input("Divide this: "), input("by this: "))
    elif choice ==5:
        loop = 0

print ("Thank you for using calculator.py")

答案 2 :(得分:0)

在python中,有一些标识规则来了解程序应该如何执行命令。这是python在函数,条件语句或for,while语句开始和结束时识别的方式。例如,在您的情况下,elif语句应该处于相同的级别"作为你的初始if语句开始:

POST messages-2017.04*/_search
{
    "size": 0,
    "query": {
        "bool": {
            "must":{
                "bool":{
                "should": [
                        {
                            "match": {
                                "RouteData": {
                                    "query": "Q25B",
                                    "type": "phrase"
                                }
                           }
                        }
                    ]
               }
            }
        }
    },
    "aggs": {
       "all_indexes": {
          "terms": {
             "field": "_index",
             "size": 100
          }
       }
    }
}