[Python] How to give a variable a "type" or "kind" in Python? [closed]

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to code a game similar to "Guess Who" with Python. I'm very inexperienced, and there's probably a simple answer, but I've been having trouble telling the computer which variables to delete after a question is answered. For example, I have 4 people in the game. Two are happy and two are sad. One happy and one sad have winky eyes, the other two have normal eyes. If the computer asks, "does your person have winky eyes", and the answer is no, I want it to delete all those with winky eyes, including any listed in the dictionary as 'happy' or 'sad' if they also have brown eyes. I know this is a horrible explanation of the problem, so I'll put my code so far.

    people = {
    "winkEyes": {"happy": ";)", "sad": ";("},
    "normalEyes": {"happy": ":)", "sad": ":(" },
    "happy": {"winky": ";)", "normal": ":)"},
    "sad": {"winky": ";(", "normal": ":("}


    I have stored every person in a dictionary, but I'm beginning to think this isn't the right choice for what I want. If the computer finds out that the person is happy, then it will delete the element sad. But it will not delete the sad faces in the winkEyes and normalEyes elements. This is my problem.

    I need the people to have multiple underlying "types" or "kinds", such as "happy" and "winky".

    Does anyone know how to do this? I'm sure there must be a way.

    Continue reading...

Compartilhe esta Página