2017-04-19 4 views
-5
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") 

これは私のコードであり、エラーがある: プリント( "+"、B "="、A + B) ^ IndentationErrorは:インデントブロックこのインデントエラーは何ですか?

プロセスが出口を終了予想コード1 と多くの人が誰も私がすべてのエラーを見つけるのを助けることができますか? 誰でも私を助けることができますか?

+5

あなたは 'def():'の後にインデントする必要があります。コロン ':')、あなたはいくつかの場所でインデントを解除する必要があります –

答えて

0

では、pythonブロックはインデントで定義されます。関数を定義した後、インデント(タブ)が必要です。

0

ほとんどすべてのインデントが間違っているだけではなく、1つの場所: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): 
    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") 
0

、プログラムはコマンドを実行する方法を知ってインデントルールがあります。これは、関数、条件文、for、while文の開始と終了をPythonが認識する方法です。例えば、あなたの場合、elif文は最初のif文の開始と同じ "レベル"でなければなりません:

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 
関連する問題