my program is simple, you enter your name, you select the desired amount of names youd like to enter and it prints out all the combinations... my only issue is not being able to add an if statement arount this couple lines of code so that the user wont be able to enter duplicate names or use any numbers in the name. i have tried a couple of things but i cant remember the exact code
names = []
for i in range(n):names.append(raw_input("Enter name "+str(i+1)+": "))
count = 0
def perm(a,k=0):
global count
if(k==len(a)):
print a
count += 1
else:
for i in xrange(k,len(a)):
a[k],a[i] = a[i],a[k]
perm(a, k+1)
a[k],a[i] = a[i],a[k]
my entire code can be found here if you'd like to paste it and run it, its kinda fun. in other words, if anyone could help me out just for the fact of where or how to achomplish this if/else statement, around the
(raw_input("Enter name "+str(i+1)+": "))
line of code. thank you all in advance
Aucun commentaire:
Enregistrer un commentaire