Code: Alles auswählen
ars = 'ars', 2
natm = 'nat-m', 2
'Asthma' : [ars, natm, ...]
Code: Alles auswählen
ars = 'ars', 2
natm = 'nat-m', 2
'Asthma' : [ars, natm, ...]
Code: Alles auswählen
from functools import partial, reduce
#:
#: Mapping of symptom to a mapping of placebo to value.
#:
SYMPTOM_TO_PLACEBOS = {
'Abmagerung': {'ars': 3, 'lyc': 2, 'merc': 2, 'nat-m': 1},
'Asthma': {'ars': 2, 'lyc': 2, 'nat-m': 2, 'phos': 3},
'Hitze': {
'ars': 1, 'bell': 3, 'nat-m': 2, 'puls': 2, 'sulf': 3, 'sulf-ac': 2
},
'Kälte': {'ars': 3, 'lyc': 1, 'merc': 2, 'sil': 3},
}
def add_common_placebos(placebos_a, placebos_b):
"""Takes two mappings of placebo to value and returns a mapping of the
placebos common to both arguments mapping to the sum of both values.
>>> add_common_placebos({'a': 1, 'b': 2, 'c': 3}, {'b': 4, 'd': 5, 'e': 6})
{'b': 6}
"""
common_keys = set(placebos_a.keys()) & set(placebos_b.keys())
return dict((k, placebos_a[k] + placebos_b[k]) for k in common_keys)
def main():
symptoms = [
symptom
for symptom in iter(partial(input, 'Gib ein Symptom ein: '), '')
if symptom in SYMPTOM_TO_PLACEBOS
]
common_placebos = reduce(
add_common_placebos, (SYMPTOM_TO_PLACEBOS[s] for s in symptoms)
)
for placebo, value in common_placebos.items():
print('{0}, mit einer Wertigkeit von {1}'.format(placebo, value))
if __name__ == '__main__':
main()
Ein blutiger Anfänger in Sachen Python bin ich zwar vielleicht nicht mehr, aber ich beschäftige mich auch erst seit einem Dreivierteljahr intensiver (neben Beruf und Familie) damit. Aus Erfahrung kann ich sagen: Keine Angst vor SQL. Es sieht komplizierter aus als es tatsächlich ist.Eliazz hat geschrieben: 1. Wie Blackjack bereits sagte: Ich bin ein blutiger Anfänger und habe nicht das nötige Know-How für SQL einbindung.
Hierzu bräuchtest du dann nur eine zusätzliche Spalte, wo dann die Wertigkeit hinterlegt ist (unter der Annahme, dass ein Heilmittel je nach Symptom eine andere Wertigkeit haben kann. Hat ein Heilmittel grundsätzlich immer die gleiche Wertigkeit, könnte man das in einer weiteren Tabelle abbilden)Eliazz hat geschrieben: 2. Am Ende gibt es für jedes Symptom bis zu 50 mögliche Mittel, welche wiederum ihre eigenen Wertigkeiten haben, das wird dann schwierig in einer Tabelle. Vorallem wenn die Anzahl der Mittel nicht immer übereinstimmt.