DeaD_EyE icon

koalitionen

DeaD_EyE | PRO | 02/23/25 08:53:05 PM UTC (Edited) | 0 ⭐ | 1321 👁️ | Never ⏰ | []
Python |

680 B

|

None

|

0 👍

/

0 👎

import itertools
 
 
def koalitionen(ergebnisse: dict, low_threshold: float, high_threshold: float):
    for n in range(2, len(ergebnisse)):
        for combo in itertools.combinations(ergebnisse.items(), r=n):
            if low_threshold <= sum(e[1] for e in combo) <= high_threshold:
                total = f"{sum(e[1] for e in combo):.1f} %"
                koalition = " | ".join([e[0] for e in combo])
                print(total, koalition, sep=" | ")
 
 
ergebnisse = {
    "cdu": 28.5,
    "afd": 20.6,
    "spd": 16.4,
    "grüne": 11.9,
    "linke": 8.6,
    # "bsw": 4.9,
    # "fdp": 4.5,
    # "sonstige": 4.6,
}
 
koalitionen(
    ergebnisse,
    50.0,
    60,
)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎