Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import re
  2. import sys
  3. name = raw_input("Please enter your name: ")
  4.  
  5.  
  6. ##
  7. while not re.match("^[Sa-zA-Z]*$", name):
  8.  
  9. if not re.match("^[Sa-zA-Z]*$", name):
  10. print "Error! Only letters a-z allowed!"
  11. name = raw_input("Please enter your name: ")
  12. else:
  13. break
  14. ##
  15.  
  16. ######################
  17. print("Hello, " + name)
  18.  
  19.  
  20.  
  21. while True:
  22. try:
  23. n = int((raw_input)("How many names would you like to enter? (between 1-9) "))
  24.  
  25. except ValueError:
  26. print("Please Enter An Integer From 1-9")
  27. continue
  28.  
  29. if n > int("9"):
  30.  
  31. print("please do not print anything higher than 9")
  32.  
  33. elif n < int("1"):
  34. print("please do not print anything lower than 1")
  35. else:
  36. break
  37.  
  38.  
  39.  
  40.  
  41. names = []
  42.  
  43. for i in range(n):names.append(raw_input("Enter name "+str(i+1)+": "))
  44.  
  45. count = 0
  46.  
  47. def perm(a,k=0):
  48. global count
  49. if(k==len(a)):
  50. print a
  51.  
  52. count += 1
  53. else:
  54. for i in xrange(k,len(a)):
  55. a[k],a[i] = a[i],a[k]
  56. perm(a, k+1)
  57. a[k],a[i] = a[i],a[k]
  58.  
  59.  
  60. if n % 2 == 0:
  61. print""
  62. perm(names)
  63. print"total combinations available: " + str(count)
  64. else:
  65.  
  66. perm(names)
  67. print"total combinations available: " + str(count)
  68. print("please enter an even number next time")
  69.  
  70. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement