Reference no: EM132355625
Question
Help with python 3! Locker Puzzle assignment.
Solve the "locker puzzle." A school has 100 students and 100 lockers. All lockers are closed on the first day of school. As the students enter, the first student (S1) opens every locker. Then the second student (S2) begins with the second locker (L2), and closes every other locker. Student S3 begins with the third locker (L3) and changes every third locker (closes it if it was open, and opens it if it was closed). Student S4 begins with locker L4 and changes every fourth locker. Student S5 begins with locker L5 and changes every fifth locker, and so on, until student S100 changes L100.
After all the students have passed through the building and changed all of the lockers, which lockers are open? Create a function calledlocker_puzzle() to find your answer. The function should print out the list of open locker numbers.
Hint: Use a list of Booleans to indicate whether a locker is open (True) or closed (False). Use main function to call it.
Note that lst = [False] * 100will make a list of 100 booleans, all set to False.
The Output should be this in this order. I've figured out the open lockers I just can't implement the function and how to call it with the main() function
1
4
9
16
25
36
49
64
81
100
Any help or feedback is welcome :-)
#locker puzzle
def locker_puzzle(lst):
num_lockers = 100
num_students = 100
num = 1
locker_list = list(range(1, 100))
locker_list = [False or True] * 100
for i in range(len(locker_list)):
locker_list.append(num**2)
num += 1
return locker_list
def main():
l= list(range(1,100))
print(locker_puzzle(l))
main()