```
def get_open_lockers(num_lockers, num_students):
list_lockers = ["open"]*num_lockers # 1st step
for k in range(2,num_students+1): # others
for i,j in enumerate(list_lockers):
if (i+1)>=(k-1):
if (i+1)%k==0:
if list_lockers[i] == "open":
list_lockers[i] = "close"
else:
list_lockers[i] = "open"
return list_lockers.count("open")
print(get_open_lockers(100, 100))
```

# Count the number of open lockers in school

Carvia Tech | May 19, 2019 | 1 min read | 18 views | Python Coding Problem

## School Daze

A group of schools has a specific number of lockers and a specific number of students. All lockers are closed on the first day of school. As students get to school they begin to play with the lockers. The first student opens every locker. The second student begins with the 2nd locker and closes every other locker. The third student starts with the third locker and changes every 3rd locker. That is, the third student opens the locker if it is closed and closes it if it is open. The 4th student starts with locker 4 and changes every 4th locker and so on. After all the students are done, display how many lockers are open.

Input | Output |
---|---|

100, 100 |
100 Lockers: 100 Students; 10 Open lockers |

10, 5 |
10 Lockers; 5 Students; 6 Open lockers |

1000, 50 |
1000 Lockers; 50 Students; 499 Open lockers |

10

###### Python Coding Problem:

- Write a program to check if the given word is Isogram & Pair isogram in python
- Write a python program to find Largest Substring that occurs more than once
- Pass the ball game: NxN matrix in python
- Write a program for Hailstone Sequence in Python
- Find perfect abundant or deficient factors in python
- Write a program to find if a number is Lychrel Number in Python

**Python Coding Problem**

###### Top articles in this category:

- Google Data Scientist interview questions with answers
- Top 100 interview questions on Data Science & Machine Learning
- Write a program to find if a number is Lychrel Number in Python
- Pass the ball game: NxN matrix in python
- Write a program for Hailstone Sequence in Python
- Closest Points
- Deploying Keras Model in Production using Flask

###### Find more on this topic:

##### Machine Learning

Data science, machine learning, python, R, big data, spark, the Jupyter notebook, and much more

Last updated 1 month ago

###### Recommended books for interview preparation:

##### Facebook Page

##### Similar Posts

- Closest Points
- Sum of the Diagonals
- How to design a customer satisfaction survey
- When using Gaussian mixture model, how do you know it is applicable
- Why use feature selection in machine learning
- What is the difference between K-mean and EM? How to decide k
- Explain a probability distribution that is not normal and how to apply that
- Google Data Scientist interview questions with answers
- Count the number of open lockers in school
- Introduction to Sorting Algorithms

Enter your email address to subscribe to this blog and receive notifications of new posts by email.