Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
166
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.  
  4. name = raw_input("Please enter your name: ")
  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. while True:
  20. try:
  21. n = int((raw_input)("How many names would you like to enter? (between 1-9) "))
  22.  
  23. except ValueError:
  24. print("Please Enter An Integer From 1-9")
  25. continue
  26.  
  27. if n > int("9"):
  28.  
  29. print("please do not print anything higher than 9")
  30.  
  31. elif n < int("1"):
  32. print("please do not print anything lower than 1")
  33. else:
  34. break
  35.  
  36. names = []
  37.  
  38. for i in range(n): names.append(raw_input("Enter name " + str(i + 1) + ": "))
  39.  
  40. count = 0
  41.  
  42.  
  43. def perm(a, k=0):
  44. global count
  45. if (k == len(a)):
  46. print a
  47.  
  48. count += 1
  49. else:
  50. for i in xrange(k, len(a)):
  51. a[k], a[i] = a[i], a[k]
  52. perm(a, k + 1)
  53. a[k], a[i] = a[i], a[k]
  54.  
  55.  
  56. if n % 2 == 0:
  57. print""
  58. perm(names)
  59. print"total combinations available: " + str(count)
  60. else:
  61.  
  62. perm(names)
  63. print"total combinations available: " + str(count)
  64. print("please enter an even number next time")
  65.  
  66. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement