Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import sys
- name = raw_input("Please enter your name: ")
- ##
- while not re.match("^[Sa-zA-Z]*$", name):
- if not re.match("^[Sa-zA-Z]*$", name):
- print "Error! Only letters a-z allowed!"
- name = raw_input("Please enter your name: ")
- else:
- break
- ##
- ######################
- print("Hello, " + name)
- while True:
- try:
- n = int((raw_input)("How many names would you like to enter? (between 1-9) "))
- except ValueError:
- print("Please Enter An Integer From 1-9")
- continue
- if n > int("9"):
- print("please do not print anything higher than 9")
- elif n < int("1"):
- print("please do not print anything lower than 1")
- else:
- break
- 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]
- if n % 2 == 0:
- print""
- perm(names)
- print"total combinations available: " + str(count)
- else:
- perm(names)
- print"total combinations available: " + str(count)
- print("please enter an even number next time")
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement