Python 3.8.2| Why do I have a : TypeError: cannot unpack non-iterable NoneType object?

FR Papi Jaaj

I'm a beginner in Python. Why do I have this error when I call this function? My function searchs the first technology (in dict_tech) which isn't already discovered (in dict_techdisc). Then, if you have the required amount of TECH Points, it calls a prompt which asks you if you want to discover the technology. If the answer is yes, it will substract the amount of TECH Points you have with the amount required, and update dict_techdisc with the same key of dict_tech. If it's no, it will stop the resquest.

dict_techdisc = {}
dict_tech = {"A":"Première lettre de l'Alphabet, Première des Voyelles.'a': Symbole de l'Are et de l'Attométrie.'A': Symbole de l'Ampère, Ancien Symbole de l'Argon.(Musique) 'A' La, dans le système de notation anglo-saxonne et germanique.'Å': Symbole de l'Angström.'À': Bombe Nucléaire de Fission."} 
dict_cout = {"A":6,"À(2)":11,"Abaca":1,"Abacule":1,"Abaisser (et ses dérivés)":13,"Abajoue":1,"Abandonner (et ses dérivés)":11,"Abaque":3,"Abasie":1}

def techachat(ptstech):
    """
Action servant à acheter une technologie pour un coût donné.
    """
    try:
        for tech, val in dict_cout.items():
            if tech in dict_cout.keys() and tech not in dict_tech.keys(): 
                if int(val) < ptstech:
                    res = 0
                    requete = ""
                    while requete != "oui" or requete != "non":
                        requete = input(f"Veux-tu acheter la technologie {tech}? (Oui, Non)")
                        if requete == "Oui":
                            ptstech -= int(val)
                            res = ptstech
                            for tech2 in dict_tech:
                                if dict_tech.get(tech2) is not None:
                                    dict_techdisc.update(dict_tech[tech2])
                                else:
                                    continue
                                break
                            time.sleep(3)
                            print(f"Vous avez bien débloqué la technologie {tech} pour un coût de {val} points TECH.")
                            time.sleep(3)
                            print(f"Il vous reste {ptstech} points TECH.")
                            time.sleep(3)
                            print("Fin de la requête")
                            print(dict_techdisc)
                            return res, dict_techdisc
                        elif requete == "Non":
                            print("Fin de la requête.")
                            return
                        else:
                            print("Réponse non valide!")
                            continue
                else:
                    print("Vous n'avez pas assez de points TECH pour pouvoir acheter la prochaine technologie!")
            else:
                continue
    except:
        print("Fin de la requête.")

Here is where I use it:

from Lanfangist import *

import time

from AvrupaBody import *

from Acte1 import *

from Sauvegarde import *

#-----Modules au dessus
#-----Code en dessous

#aventurech1()
dict_tech = {"A":"Première lettre de l'Alphabet, Première des Voyelles.'a': Symbole de l'Are et de l'Attométrie.'A': Symbole de l'Ampère, Ancien Symbole de l'Argon.(Musique) 'A' La, dans le système de notation anglo-saxonne et germanique.'Å': Symbole de l'Angström.'À': Bombe Nucléaire de Fission."} 
dict_cout = {"A":6,"À(2)":11,"Abaca":1,"Abacule":1,"Abaisser (et ses dérivés)":13,"Abajoue":1,"Abandonner (et ses dérivés)":11,"Abaque":3,"Abasie":1}

_ptstech = 50
_argent = 0
dict_techdisc = {}
_argent, dict_techdisc = techachat(_ptstech)
_ptstech = _argent
print(_ptstech)
print(dict_techdisc)
_argent, dict_techdisc = techachat(_ptstech)
_ptstech = _argent
print(_ptstech)
print(dict_techdisc)

And here is the error:

        _argent, dict_techdisc = techachat(_ptstech)
TypeError: cannot unpack non-iterable NoneType object
Simon Martineau

If you write _argent, dict_techdisc = techachat(_ptstech), it means you expect your function to return a list or tuple of size 2. However, your function does not always return a two-element iterable. When it returns None, which happens when no return statements are encountered, an exception is raised. It's as if you were writing x, y = None. Consider surrounding the function call with a try block.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TypeError: cannot unpack non-iterable NoneType object

-- TypeError: cannot unpack non-iterable NoneType object

PyAutoGui TypeError: cannot unpack non-iterable NoneType object

TypeError: cannot unpack non-iterable NoneType object Error

I am getting: TypeError: cannot unpack non-iterable NoneType object, but I am returning a tuple

Python error- cannot unpack non-iterable NoneType object

Why am I getting TypeError: cannot unpack non-iterable builtin_function_or_method object?

Python Django: TypeError: cannot unpack non-iterable MatchAll object

Python: TypeError: cannot unpack non-iterable int object

Python TypeError: cannot unpack non-iterable bool object

Python / TypeError: cannot unpack non-iterable Jugador object

TypeError: cannot unpack non-iterable int object (Python)

This error occurs when I'm running my code on terminal "TypeError: cannot unpack non-iterable NoneType object"

Find smaller number from 2 provided - works, but throws an error. TypeError: cannot unpack non-iterable NoneType object

Calling local variable causes TypeError: cannot unpack non-iterable NoneType object

TypeError: cannot unpack non-iterable NoneType object when running a sorting function

Error occurs running code in terminal "TypeError: cannot unpack non-iterable NoneType object"

How do I create a field in my serializer to avoid a "TypeError: cannot unpack non-iterable Address object" error?

TypeError: cannot unpack non-iterable GetColorImage object

tensorflow TypeError: cannot unpack non-iterable float object

TypeError: cannot unpack non-iterable int object

TypeError at /cart/ cannot unpack non-iterable Cart object

TypeError: cannot unpack non-iterable bool object

TypeError: cannot unpack non-iterable Lexer object

"TypeError: cannot unpack non-iterable int object" with filter function

How to fix TypeError: cannot unpack non-iterable Button object

I am getting a "TypeError: cannot unpack non-iterable int object"

cannot unpack non-iterable numpy.float64 object python3 opencv

Python error "cannot unpack non-iterable int object"