Skip to content

Instantly share code, notes, and snippets.

@P3nny
Created December 21, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save P3nny/91c8b212cc4467f69e0e to your computer and use it in GitHub Desktop.
Save P3nny/91c8b212cc4467f69e0e to your computer and use it in GitHub Desktop.
Wichtel-Programm für die Familienweihnachtsfeier
# -*- coding: UTF-8 -*-
# Patricia Ennenbach - 15-12-21 - Wichteln
# Aufgaben:
# - Jedes Kind soll einem Kind etwas schenken
# - Kinder sollen sich nicht selbst beschenken
# - Kinder sollen nicht ihre Geschwister beschenken
# - Jedes Kind soll nur einmal beschenkt werden
# Mein Problem:
# Wenn z.B "Kind == Wichtel" ist, müsste für dieses Kind ein neuer Wichtel gesucht werden, mein Weg "kinder.append(kind)" ist aber nicht ideal.
# Weißt Du eine bessere Lösung?
import random
random.seed()
familiendict = {
'nina': ['Erik', 'Mira'],
'haupi': ['Helena', 'Clara'],
'philipp': ['Romy', 'Simon'],
'frick': ['Melina', 'Manuel'],
'tim': ['Hannah', 'Leah'],
'verena': ['Judith']
}
kinder = ['Erik', 'Mira', 'Helena', 'Clara', 'Romy', 'Simon', 'Melina', 'Manuel', 'Hannah', 'Leah', 'Judith']
print(len(familiendict))
print(familiendict.values())
print(len(kinder))
wichteldict = {}
for kind in kinder:
wichtel = random.choice(kinder)
print(kind, wichtel)
if wichtel == kind:
print("Wichtel = Kind, nochmal!")
kinder.append(kind)
elif wichtel != kind:
test = [kind, wichtel]
test2 = [wichtel, kind]
print(test,test2)
if test in familiendict.values() or test2 in familiendict.values():
kinder.append(kind)
elif test and test2 not in familiendict.values():
test3 = wichtel
print("x",wichtel)
print(test3)
if test3 in wichteldict.values():
kinder.append(kind)
elif test3 not in wichteldict.values():
wichteldict[kind] = wichtel
print(wichteldict)
print(len(wichteldict))
print(len(kinder))
#test
list1=[]
for value in wichteldict.values():
if value not in list1:
list1.append(value)
elif value in list1:
print("Doppelt:", value)
print(len(list1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment