spacepaste

  1.  
  2. def stepdirection(start, end):
  3. # determine if we are stepping up or down
  4. if start > end:
  5. end -= 1
  6. step = -1
  7. else:
  8. end += 1
  9. step = None
  10. return [start, end, step]
  11. def crackiterable(start=-1, end=100):
  12. try:
  13. totalcount = 0
  14. cracklepopcount = 0
  15. snapcount = 0
  16. cracklecount = 0
  17. for number in range(stepdirection(start, end)):
  18. totalcount += 1
  19. if number % 3 == 0 and number % 5 == 0:
  20. print("{0} - Cracklepop!\n").format(number)
  21. cracklepopcount += 1
  22. elif number % 3 == 0 and not number % 5 == 0:
  23. print("{0} - Snap!\n").format(number)
  24. snapcount += 1
  25. elif number % 5 == 0 and not number % 3 == 0:
  26. print("{0} - Crackle!\n").format(number)
  27. cracklecount += 1
  28. else:
  29. print("{0}\n").format(number)
  30. print("""
  31. In the range from {0} to {1}, there were:
  32. {2} Snaps, {3} Crackles, and {4} Cracklepops""").format(
  33. start, end, snapcount, cracklecount, cracklepopcount)
  34. except TypeError:
  35. print("You've not provided an integer for start and end length")
  36. raise
  37. except:
  38. print("Unexpected error!")
  39. raise
  40. crackiterable()
  41.