Post: Need help with Python Project
10-14-2011, 12:08 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); I have this school project where I need to make groups randomly with python...we have most of it set up and running fine but I wanted to know if someone could help me get it so that it will not print the same name twice as in vinny vinny or joe joe I do NOT want it to post the same name twice but I cannot find a command to help me out.

Heres the python Code:


import random
mylist = ['anthony', 'kris', 'james', 'vinny', 'joe']
randomList1 = random.randrange(0,len(mylist))
randomList2 = random.randrange(0,len(mylist))
name2 = mylist[randomList1]
name3 = mylist[randomList2]
print 'The group will consist of', name2, 'and', name3,'. '


help will be REALLY appreciated! Thank You
(adsbygoogle = window.adsbygoogle || []).push({});
10-14-2011, 12:18 AM #2
Alfa
Banned
import random
mylist = ['anthony', 'kris', 'james', 'vinny', 'joe']
print 'The group will consist of', random.randrange(0,len(mylist)), 'and', random.randrange(0,len(mylist)),'. '

ionno just a guess
10-14-2011, 10:23 AM #3
naa man...thats giving me numbers now lol
10-17-2011, 08:17 PM #4
glitchplz
Samurai Poster
Here you go, use an if statement:

    
import random
mylist = ['anthony', 'kris', 'james', 'vinny', 'joe']
randomList1 = random.randrange(0,len(mylist))
randomList2 = random.randrange(0,len(mylist))
name2 = mylist[randomList1]
name3 = mylist[randomList2]
if name3 == name2:
randomList2 = random.randrange(0,len(mylist))
name3 = mylist[randomList2]
print("The group will consist of", name2, "and", name3,". ")

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo