Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- totalLockers = 100
- filePath = "lockerFile.csv"
- # create the list to store the state of each of the lockers
- lockers = []
- # create a function that will toggle the state of a locker in the list
- def toggleLocker(lockerID):
- if lockers[lockerID] == "Closed":
- lockers[lockerID] = "Open"
- else:
- lockers[lockerID] = "Closed"
- # create a function that will tidy up the list and write it to the file
- def writeRow():
- with open(filePath, 'a') as file:
- lockerString = str(lockers)
- lockerString = lockerString.replace('[', '')
- lockerString = lockerString.replace(']', '')
- lockerString = lockerString.replace('\'', '')
- lockerString = lockerString + '\n'
- file.write(lockerString)
- #setup all lockers as closed
- for i in range(totalLockers += 1):
- lockers.append("Closed")
- # for each number
- for a in range(totalLockers):
- # increase a by 1 to skip 0
- a += 1
- # for each locker
- for b in range(totalLockers):
- # increase a by 1 to skip 0
- b += 1
- # check if the current locker is divisible by the factor currently being used
- if b % a == 0:
- # if, then toggle the current locker number (b)
- toggleLocker(b)
- # write the completed row to the file
- writeRow()
Add Comment
Please, Sign In to add comment