2017-11-14 12 views
-4

これはコード学習の私の最初の日です。私はこのコードを試したが、なぜ失敗したのか分からない。すべてのヘルプははるかに高く評価されていますelse ifとelifが私のpythonコードのために働いていない

a=int(input()) 

if a>10: 
    print("your number is greater than 10") 
    else: 

私はSyntaxError: invalid syntax

+2

1)あなたのインデントが間違っています( 'else:'はインデントしてはいけません)2) 'else:'の後ろにあるステートメントが必要です。 –

+0

インデントを修正します。 –

+3

'else:'文も入れずに 'print'文をインデントする必要があります – EdChum

答えて

0

あなたのインデントが間違って取得します。それは次のようになります。

a=input() 
if a>10: 
    print("your number is greater than 10") 
else: 
    # You didn't have anything in your else statement so either remove it or add a statement... 
    print("your number is <= 10") 

python documentation on indentationを参照してください。

3
if a>10: 
    print("your number is greater than 10") #indent the print statement 
else: 
    print('Not greater than 10') 
    #you need to perform an action inside the else condition 
0

あなたはインデントエラーを持っている:

elifelse部分は任意であり、 elifelse: if condition:を意味
if condition: 
    code... 
elif condition: 
    another code... 
else: 
    last code... 

PS:int(input())を使用してください。そうしないと文字列が得られますが、intはありません。

関連する問題