M
M. Clift
Hi All,
Back again...
This code works nicely giving a list of names with no name repeated at a
space of 3 i.e. you won't get 'Bob','Bob' or 'Bob','Sue','Bob'.
What I'd like to do is add a condition to it which says that although the
names are different 'Bob' and 'Mary' are equal and so it won't generate
'Bob', 'Rita','Mary'
I've tried various ways to do it, but with no joy. Any help appreciated.
Thanks, M
<code>
from random import *
Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? ")))
state = [None,None]
nextName = {'Bob':['Rita','Sue'],\
'Rita':['Mary','Sue','Bob'],\
'Sue':['Rita','Mary','Bob'],\
'Mary':['Sue','Rita']}
Name_List = []
tmp = choice(('Bob','Rita','Sue','Mary))
for x in Name_Number:
print state
while tmp in state[0:2]:
tmp = choice(nextName[Name_List[-1]])
print tmp, ", ",
print
print "Name ",x+1," is ", tmp
Name_List.append(tmp)
state[x%2] = tmp
print Name_List
<code>
Back again...
This code works nicely giving a list of names with no name repeated at a
space of 3 i.e. you won't get 'Bob','Bob' or 'Bob','Sue','Bob'.
What I'd like to do is add a condition to it which says that although the
names are different 'Bob' and 'Mary' are equal and so it won't generate
'Bob', 'Rita','Mary'
I've tried various ways to do it, but with no joy. Any help appreciated.
Thanks, M
<code>
from random import *
Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? ")))
state = [None,None]
nextName = {'Bob':['Rita','Sue'],\
'Rita':['Mary','Sue','Bob'],\
'Sue':['Rita','Mary','Bob'],\
'Mary':['Sue','Rita']}
Name_List = []
tmp = choice(('Bob','Rita','Sue','Mary))
for x in Name_Number:
print state
while tmp in state[0:2]:
tmp = choice(nextName[Name_List[-1]])
print tmp, ", ",
print "Name ",x+1," is ", tmp
Name_List.append(tmp)
state[x%2] = tmp
print Name_List
<code>