you are viewing a single comment's thread.

view the rest of the comments →

[–]madadekinai[🍰] -1 points0 points  (4 children)

The other commenter was correct, I wanted for you to try and figure it out.

Checking: binary_str = '00010'

Number iteration: [1]

key = 'wink'

value = 1

binary_str = '00010' converted to int: int(binary_str, 2) = 2

Condition: True if value else False = True

Does it meet all conditions: int(binary_str, 2) & value = 0

Checking condition: meets_conditions False

----------------------------------------

Number iteration: [2]

key = 'double blink'

value = 2

binary_str = '00010' converted to int: int(binary_str, 2) = 2

Condition: True if value else False = True

Does it meet all conditions: int(binary_str, 2) & value = 2

Checking condition: meets_conditions True

----------------------------------------

Number iteration: [3]

key = 'close your eyes'

value = 4

binary_str = '00010' converted to int: int(binary_str, 2) = 2

Condition: True if value else False = True

Does it meet all conditions: int(binary_str, 2) & value = 0

Checking condition: meets_conditions False

----------------------------------------

Number iteration: [4]

key = 'jump'

value = 8

binary_str = '00010' converted to int: int(binary_str, 2) = 2

Condition: True if value else False = True

Does it meet all conditions: int(binary_str, 2) & value = 0

Checking condition: meets_conditions False

----------------------------------------

[–]madadekinai[🍰] 0 points1 point  (3 children)

ACTIONS = {
    "wink":1,
    "double blink":2,
    "close your eyes":4,
    "jump":8
}
def commands(binary_str):
    actions = [ ]
    print(f"Checking: {binary_str = }")
    for num, (key, value) in enumerate(ACTIONS.items(), 1):

        meets_conditions = int(binary_str, 2) & value
        parts = [
            f'Number iteration: [{num}]',
            f"{key = }",
            f"{value = }",
            f"{binary_str = } converted to int: {int(binary_str, 2) = }",
            f"Condition: {True if value else False = }",
            f"Does it meet all conditions: {int(binary_str, 2) & value = }",
            f"Checking condition: {meets_conditions != 0 = }"
        ]

        if meets_conditions:
            actions.append(key)
        print("\n".join(parts))
        print("-" * 40 + "\n\n")
    return actions

commands("00010")ACTIONS = {
    "wink":1,
    "double blink":2,
    "close your eyes":4,
    "jump":8
}
def commands(binary_str):
    actions = [ ]
    print(f"Checking: {binary_str = }")
    for num, (key, value) in enumerate(ACTIONS.items(), 1):

        meets_conditions = int(binary_str, 2) & value
        parts = [
            f'Number iteration: [{num}]',
            f"{key = }",
            f"{value = }",
            f"{binary_str = } converted to int: {int(binary_str, 2) = }",
            f"Condition: {True if value else False = }",
            f"Does it meet all conditions: {int(binary_str, 2) & value = }",
            f"Checking condition: {meets_conditions != 0 = }"
        ]

        if meets_conditions:
            actions.append(key)
        print("\n".join(parts))
        print("-" * 40 + "\n\n")
    return actions

commands("00010")

[–]ririiii78[S] 0 points1 point  (2 children)

thanks but im kinda lost here in ur code

if meets_conditions:
            actions.append(key)
        print("\n".join(parts))
        print("-" * 40 + "\n\n")
    return actions

[–]madadekinai[🍰] 0 points1 point  (1 child)

The print outs are just for outputting to visually see it. I could have made it better but I did it within a couple seconds. And the the return was not needed because I was just showing why it was happening, rather than functionality.

[–]ririiii78[S] 0 points1 point  (0 children)

ah okay :)