2014-07-26 58 views
0

顯然,我的代碼有問題。當我使用Python 3.3.3 Shell運行下面的模塊時,出現錯誤SyntaxError: expected an indented block。然後,第7行SyntaxError:預計會出現縮進塊

def user_input(): 
    print('[1]: ASCII to Binary') 
    print('[2]: Binary to ASCII') 
    user_input = input('Please choose [1] or [2]: ') 
    if user_input == ('1', '[1]'): 
     # 
    elif user_input == ('2', '[2]'): 
     # 
    else: 
     print('Please enter a valid input...') 
     user_input() 
+0

用'pass's更換'#'秒。 – arshajii

回答

2

必須 IDLE亮點elif在每個ifelif塊實際的代碼,你不能只用一個註釋。

使用pass在這種情況下:

if user_input == ('1', '[1]'): 
    pass 
elif user_input == ('2', '[2]'): 
    pass 
else: 
    print('Please enter a valid input...') 
    user_input() 
+0

好的,謝謝!那工作...再一個問題。對於'user_input = input('請選擇[1]或[2]:')',我會用'str(input('input'))'而不是? –

+0

@JamesLynch:不,在Python 3中,'input()'* already *返回一個字符串;將其轉換爲相同類型沒有意義。 –

+0

好的。因爲'user_input = input('請選擇[1]或[2]:'),因此我不一定指'str(input('input'))',我的意思是我需要爲'input'添加一個參數。 '請求一個號碼,但我不確定我會怎麼做 –