Last active
December 1, 2018 23:13
-
-
Save jonasryberg/dec72033034e9741aced40ec07b0ef44 to your computer and use it in GitHub Desktop.
Lottar julklappspar från en lista av inmatade namn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import random | |
import sys | |
xlist = list(sys.argv) | |
xlist.remove('hemligtomte.py') | |
tomtarInput = list(xlist) | |
mottagareInput = list(xlist) | |
kontroll = True | |
while kontroll == True: | |
tomtar = list(tomtarInput) | |
mottagare = list(mottagareInput) | |
mottagareSlump = [] | |
resultat = [] | |
for i in range (len(mottagare)): | |
temp = random.choice(mottagare) | |
mottagareSlump.append(temp) | |
mottagare.remove(temp) | |
for i in range (len(mottagareSlump)): | |
if tomtar[i] == mottagareSlump[i]: | |
kontroll = True | |
break | |
else: | |
kontroll = False | |
print('') | |
for i in range (len(mottagareSlump)): | |
print (tomtar[i] + ' är hemlig tomte åt ' + mottagareSlump[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
fler = True | |
tomtarInput=[] | |
while fler == True: | |
tomtarInput.append(input('Mata in ett namn: ')) | |
if input('Vill du mata in ett namn till? (j/n): ') == 'j': | |
fler = True | |
else: | |
if len(tomtarInput)%2==0: | |
break | |
else: | |
print('Det måste vara ett jämt antal tomtar!') | |
fler = True | |
kontroll = True | |
while kontroll == True: | |
tomtar = list(tomtarInput) | |
mottagare = list(tomtarInput) | |
mottagareSlump = [] | |
resultat = [] | |
for i in range (len(mottagare)): | |
temp = random.choice(mottagare) | |
mottagareSlump.append(temp) | |
mottagare.remove(temp) | |
for i in range (len(mottagareSlump)): | |
if tomtar[i] == mottagareSlump[i]: | |
kontroll = True | |
break | |
else: | |
kontroll = False | |
print('') | |
print('+++++++++++++++++++++++++++++++++++++++++') | |
for i in range (len(mottagareSlump)): | |
print (tomtar[i] + ' är hemlig tomte åt ' + mottagareSlump[i]) | |
print('+++++++++++++++++++++++++++++++++++++++++') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment