2017-09-19 13 views
1

単語を入力すると、exceptブロックのコードは実行されません。
それは言う:UnboundLocalError:割り当て
前に参照のローカル変数「アイテム」ここに私のコードです:UnboundLocalError:代入前に参照されるローカル変数 'items' - Python3

def inputSome(): 
    gundam = [] 
    try: 
     items = int(input("How many items you want to input? \n")) 

    except ValueError: 
     print("Input a number literal not words u stupid!, you input {}".format(items)) 
     inputSome() 
    while len(gundam) < items: 
     userIn = input("Input some: ") 
     gundam.append(userIn) 
     print("You input: {}".format(userIn)) 

    print(gundam) 

    input_again = input("Want to input again? [Y/N] ") 
    if input_again.lower() != 'n': 
     inputSome() 
    else: 
     print("See ya sucka!") 
inputSome() 

答えて

0

例外は、値が割り当てれることは決してありませんint(input("How many items you want to input? \n"))ので、アイテムの計算中に発生したため、このエラーが発生しました。

エラーメッセージに入力した内容を取得するには、別の行に分割します。

raw_items = input("How many items you want to input? \n") 
items = int(raw_items) 
関連する問題