Python Forum
Someone help please ??? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Someone help please ??? (/thread-3349.html)



Someone help please ??? - TheSpalekUk - May-16-2017

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


RE: Someone help please ??? - sparkz_alot - May-16-2017

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)))



RE: Someone help please ??? - buran - May-16-2017

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.


RE: Someone help please ??? - zivoni - May-16-2017

(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.


RE: Someone help please ??? - buran - May-17-2017

@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


RE: Someone help please ??? - TheSpalekUk - May-17-2017

Thank you everyone for answering my question ! :P
It helped a lot...