

アーチェリー用のプレイヤーの名前とIDを入力した後、当たった場所を入力させて得点を計算し、  
得点の多い順に並べるプログラムを制作しているのですが、いざ動かそうとしたら

[code]

    ValueError: not enough values to unpack (expected 13, got 12)
    
[/code]

という見慣れないエラーが出てしまいました。

調べるとどうやら「変数の数と要素の数が一致していない」とこのエラーが出ると書いてありましたが、関数 `set_values` の戻り値を

[code]

    return Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,Noofarrows,NoofLays,Podium
    
[/code]

から

[code]

    return Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,score,Noofarrows,NoofLays,Podium
    
[/code]

にするとそもそも動かなくなってしまいます。  
このエラーに関する解決策や改善点を教えてくれると幸いです。

[code]

    import datetime
    
    def set_up_players() :
        Assignment = True
        Memberlist = [] # Local  list
        MemberID = []   # Local  list
        while Assignment == True :
            print("")
            membership = str(input("Are you assigned already? Answer Y for 'Yes' N for 'No' :"))
            if membership == "Y" :
                y1 = int(input("Enter your year to assign your membership. :"))
                m1 = int(input("Enter your month to assign your membership. :"))
                d1 = int(input("Enter your day to assign your membership. :"))
                dt1 = datetime.datetime(year=y1, month=m1, day=d1)
                time = datetime.datetime.now() - dt1
                daytime = int((time.days))
                print(daytime)
                if daytime > 1096 :
                    print("You need to renew your membership.")
                    print("Go to office to renew you membership card.")
                else :
                    print("Welcom back to our Archely club")
            elif membership == "N" :
                check = False
                print("You need to make your membership")
                name = str(input("Enter your name. :"))
                while check == False :
                    id = str(input("Enter any 5 digit number :"))
                    if (id in MemberID) == True:
                        print ("Sorry it's already in list, Try again.")
                    else :
                        check = True
                Memberlist.append(name)
                MenberID.append(id)
            else :
                print("Answer in Y or N.")
            print("")
            Assign = str(input("Finish assignment?? Answer Y for 'Yes' N for 'No' : "))
            if Assign == "N" :
                Assignment = True
            elif Assign == "Y" :
                Assignment = False
            else :
                print("Answer in Y or N.")
    
    
        return Memberlist,MemberID # 多分問題ナシ
    
    def sign_up_players(MemberID) :
        Playerlist = []
        PlayerID = []
        player_count = 0
        while player_count == 5:
            id = str(input("Enter your  5 digit ID. :"))
            if (id in MemberID) == True:
                name = str(input("Enter your name. :"))
                Playerlist.append(name)
                PlayerID.append(id)
                player_count = player_count + 1
                print(player_count)
            else :
                print("Sorry but Register first.")
    
    
        return MemberID,Playerlist,PlayerID
    
    def set_score(NoofPlayer) :
        score = []
        counter = NoofPlayer 
        for i in range (counter) :
            score.append(0)
        return NoofPlayer, score
    
    def set_values () :
        Memberlist,MemberID = set_up_players()
        MemberID,Playerlist,PlayerID = sign_up_players(MenberID)
        NoofPlayer = int(len(Playerlist))
        maxshoot = 5
        set_score(NoofPlayer)
        Nooftargets = NoofPlayer
        NoofPG = NoofPlayer
        Round = 5
        Noofarrows = 1*Round*NoofPlayer
        NoofLays = NoofPlayer
        Podium = NoofPlayer
        return Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,Noofarrows,NoofLays,Podium　#戻り値をいじくったのはこの関数です
    
    def Allocate_Equipment(NoofPlayer) :
        ownarrows = []
        ownbows = []
        ownPG = []
        co = NoofPlayer
        while co > 0 :
            arrows = str(input("Do you have your own arrows? Answer Y for 'Yes' N for 'No' :'"))
            if arrows == "Y" :
                ownarrows.append(yes)
            else :
                ownarrows.append(no)
            PG = str(input("Do you have your own PG? Answer Y for 'Yes' N for 'No' :'"))
            if PG == "Y" :
                ownPG.append(yes)
            else :
                ownPG.append(no)
            bows = str(input("Do you have your own bow? Answer Y for 'Yes' N for 'No' :'"))
            if bows == "Y" :
                ownbows.append(yes)
            else :
                ownbows.append(no)
            co = co - 1
        print(ownarrows,ownPG,ownbows)
    
        return NoofPlayer, ownarrows, ownbows, ownPG
    
    def shooting_arrows (Playerlist,NoofPlayer,Round,score) :
        RoundTime = 0
        while Round > RoundTime :
            PlayerShoot = 0
            while PlayerShoot < Round :
                CurrentPlayer = 1
                while NoofPlayer > CurrentPlayer :
                    Player_shoot_arrow(Playerlist,CurrentPlayer)
                    Updata_score(score,CurrentPlayer,hitplace)
                    Displayscore(Playerlist,NoofPlayer,score)
                    CurrentPlayer = CurrentPlayer + 1
                PlayerShoot = PlayerShoot + 1
            RoundTime = RoundTime + 1
    
    
        return Playerlist,NoofPlayer,Round,score,RoundTime,PlayerShoot,CurrentPlayer
    
    def Player_shoot_arrow(Playerlist,CurrentPlayer) :
        print("It's "  , Playerlist[CurrentPlayer],  "'s turn.")
        hitplace = str(input("Where did you get? :"))
        return Playerlist,CurrentPlayer,hitplace
    
    def Updata_score(score,CurrentPlayer,hitplace) :
        if hitplace == "A":
            score[CurrentPlayer] = score[CurrentPlayer] + 100
        elif hitplace == "B":
            score[CurrentPlayer] = score[CurrentPlayer] + 50
        elif hitplace == "C":
            score[CurrentPlayer] = score[CurrentPlayer] + 10
    
    
        return score,CurrentPlayer,hitplace
    
    def Displayscore(Playerlist,NoofPlayer,score) :
        for i in range (NoofPlayer):
            print(Playerlist[NoofPlayer], + "'s score is " , + score[NoofPlayer])
    
        return Playerlist,NoofPlayer,score
    
    def score_board(Playerlist,NoofPlayer,Podium,score) :
        Displayscore(Playerlist,NoofPlayer,score)
        scorelist = []
        scorelist = score
        score.sort(reverse=True)
        Podium = len(score)
        third = score[2]
        second = score[1]
        first = score[0]
        print("Third Player is "  , Playerlist[scorelist.index(third)] ,  "who get " , scorelist[2])
        print("Third Player is "  , Playerlist[scorelist.index(second)] ,  "who get " , scorelist[1])
        print("Third Player is "  , Playerlist[scorelist.index(first)] ,  "who get " , scorelist[0])
        return Playerlist,NoofPlayer,Podium,score,scorelist
    
    
    Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,score,Noofarrows,NoofLays,Podium = set_values ()# ValueError: not enough values to unpack (expected 13, got 12) 
    Allocate_Equipment(NoofPlayer)
    Playerlist,NoofPlayer,Round,score = shooting_arrows (Playerlist,NoofPlayer,Round,score)
    score_board(Playerlist,NoofPlayer,Podium,score)
    
[/code]


CC BY-SA 4.0
2019-12-20T09:03:04.523
61617
2019-12-20T12:55:53.233
2019-12-20T12:55:53.233
3060
36859
question
python python3
Pythonで "ValueError: not enough values to unpack" エラーが発生する


エラーの意味は、set_values関数の戻り値は12個だが、13個あるかのように書いているため変数格納できないという意味です。

[code]

    Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,score,Noofarrows,NoofLays,Podium = set_values ()
    
[/code]

ここで13個戻り値を期待しているのに、そもそも関数は

[code]

    def set_values () :
        Memberlist,MemberID = set_up_players()
        MemberID,Playerlist,PlayerID = sign_up_players(MenberID)
        NoofPlayer = int(len(Playerlist))
        maxshoot = 5
        set_score(NoofPlayer)
        Nooftargets = NoofPlayer
        NoofPG = NoofPlayer
        Round = 5
        Noofarrows = 1*Round*NoofPlayer
        NoofLays = NoofPlayer
        Podium = NoofPlayer
        return Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,Noofarrows,NoofLays,Podium　#戻り値をいじくったのはこの関数です
    
[/code]

12個しか戻り値を返していないため不整合が起きています

どう直すかですが、set_scoreの戻り値を関数内で受け取って返せば良いと思います。

[code]

    def set_values () :
        Memberlist,MemberID = set_up_players()
        MemberID,Playerlist,PlayerID = sign_up_players(MenberID)
        NoofPlayer = int(len(Playerlist))
        maxshoot = 5
        _, score = set_score(NoofPlayer) # ココ
        Nooftargets = NoofPlayer
        NoofPG = NoofPlayer
        Round = 5
        Noofarrows = 1*Round*NoofPlayer
        NoofLays = NoofPlayer
        Podium = NoofPlayer
        return Memberlist,MemberID,Playerlist,PlayerID,NoofPlayer,maxshoot,Nooftargets,NoofPG,Round,score,Noofarrows,NoofLays,Podium # 返り値も直す
    
[/code]


CC BY-SA 4.0
2019-12-20T11:21:57.180
61623
2019-12-20T11:28:52.897
2019-12-20T11:28:52.897
26558
26558
61617
answer