Guest User

Untitled

a guest
Feb 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. totalLockers = 100
  2. filePath = "lockerFile.csv"
  3.  
  4. # create the list to store the state of each of the lockers
  5. lockers = []
  6.  
  7. # create a function that will toggle the state of a locker in the list
  8. def toggleLocker(lockerID):
  9. if lockers[lockerID] == "Closed":
  10. lockers[lockerID] = "Open"
  11. else:
  12. lockers[lockerID] = "Closed"
  13.  
  14. # create a function that will tidy up the list and write it to the file
  15. def writeRow():
  16. with open(filePath, 'a') as file:
  17. lockerString = str(lockers)
  18. lockerString = lockerString.replace('[', '')
  19. lockerString = lockerString.replace(']', '')
  20. lockerString = lockerString.replace('\'', '')
  21. lockerString = lockerString + '\n'
  22. file.write(lockerString)
  23.  
  24. #setup all lockers as closed
  25. for i in range(totalLockers += 1):
  26. lockers.append("Closed")
  27.  
  28. # for each number
  29. for a in range(totalLockers):
  30. # increase a by 1 to skip 0
  31. a += 1
  32. # for each locker
  33. for b in range(totalLockers):
  34. # increase a by 1 to skip 0
  35. b += 1
  36. # check if the current locker is divisible by the factor currently being used
  37. if b % a == 0:
  38. # if, then toggle the current locker number (b)
  39. toggleLocker(b)
  40. # write the completed row to the file
  41. writeRow()
Add Comment
Please, Sign In to add comment