Python Forum

Full Version: Someone help please ???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to make a lottery ticket simulator but i have one issue...
i want the program not to print only Names, but surnames as well right after the names...
But it gives me this error: 

Error:
Traceback (most recent call last):   File "C:\Users\spale\Desktop\SandBox.py", line 8, in <module>     Winners1 = random.choice(Names,Surnames) TypeError: choice() takes 2 positional arguments but 3 were given
How do i fix this ???

import random

print("\nWinners of todays lottery are...")

Names = ["Adolf","Tomas","Ben","Daniel","Alex","Samantha","Nicola","Angel","Blake","Guy","John","David","Julia","Romeo","Elizabeth","Jasmin","Adam","Eva","Sonia","Malika","Trump"]
Surnames = ["Hitler","Spalek","Weird","Rowland","Frosbrook","Chandler","Smith","Who","Jones","Somebody","English","Okwiet","Trump","Donaldson","Jackson","Minerson","Slavik"]

Winners1 = random.choice(Names,Surnames)
Winners2 = random.choice(Names,Surnames)
Winners3 = random.choice(Names,Surnames)

def Winners():
    print(Winners1)
    print(Winners2)
    print(Winners3)

Winners()
Thank you for taking your time to help me sort out the issue!
i Do really appreciate it! Thank you :P
You could either do this:

Winners1 = random.choice(Names) + random.choice(Surnames)
or

def Winners():
    print("Winner 1: {} {}".format(random.choice(Names), random.choice(Surnames)))
or
winner = random.choice(zip(Names,Surnames))
print('Winner: {}'.format(' '.join(winner)))
however it's better to use different data container, e.g. dict, named tupple, etc. rather than two separate lists.
(May-16-2017, 08:32 PM)buran Wrote: [ -> ]or
winner = random.choice(zip(Names,Surnames))
print('Winner: {}'.format(' '.join(winner)))
however it's better to use different data container, e.g. dict, named tupple, etc. rather than two separate lists.

random.choice() does not work on zip in python3 (no len defined), so converting it could be necessary.

Sparkz' and yours solutions are rather different, as first gives "unpaired" names, while second "paired" ones.
@zivoni: nice catch. It is  my mistake, probably I tested it only with python2. For the sake of completeness So the python3 code would be

winner = random.choice(list(zip(Names,Surnames)))
print('Winner: {}'.format(' '.join(winner)))
The recommendation to use different data structure still stands
Thank you everyone for answering my question ! :P
It helped a lot...