Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write it using python A HOTEL with 1000 rooms has 1000 waiters. Each waiter and

ID: 3904936 • Letter: W

Question

Write it using python A HOTEL with 1000 rooms has 1000 waiters. Each waiter and room is given a number from 1- 1000 Initially, waiter with number 1 goes and closes doors of all rooms. After that waiter with number 2 goes and changes the state of doors corresponding to multiples of that 2. After that waiter number 3 goes and changes the state of doors corresponding to multiples of 3 So on and so forth Find the number of doors that are open after the 1000th waiter has returned. NOTE: Changes the state of door means that opened doors are closed and closed doors ae opened.

Explanation / Answer


list = []
for i in range(1001):
    list.append(0)      
    # 0 - open 1-closed
  
for i in range(1,1001):
    for j in range(1,1001):
        if i == 1:
             list[j] = 1
        else:
           if j % i == 0:
              if list[j] == 0:
                 list[j] = 1
              if list[j] == 1:
                 list[j] = 0

count = 0
for i in range(1,1001):
    if list[i] == 0:
       count = count + 1

print("Number of doors open:",count)
           
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote