samedi 23 juin 2018

Random Function

So, I am a beginner in Python and I wanted to try something out. I want to make a for loop with random strings in it. I want the names not to repeat themselves and the prices can occur twice (we were with 5 people and there were 2 drill-motor and 2 Dc-motors to give away). So, 4 people would get a price, 2 people get the drill-motors and 2 people get the DC-motors. How can I do this? Because when I run, the random.sample repeats itself every time it runs a part of the loop and some names and prices occur to often. Thus, I want the names to occur once and each price twice.

Thanks for your help.

This is the code:

import random

price=["You have won the drill-motor" , "You have won the DC motor"]

Names = ["Hilmi", "Joris", "Isa", "Dennis", "Jasper"]

for i in range (len(Names)-1): print(*random.sample(Names,1), *random.sample(price,1))




Aucun commentaire:

Enregistrer un commentaire