Question 15
You are inside the lift of a building. There are 8 levels in the building: [−3,−2,−1,0,1,2,3,4] The number 0 is the ground floor. Positive numbers correspond to floors above the ground floor, negative numbers correspond to basement levels below the ground floor. The lift has only two buttons. The button U will take you one level up and the button D will take you one level down. You make a sequence of presses. # presses contains the sequence of button presses made by you presses = 'UDDUUUDDUDU' floor = 0 index = 0 while index < len(presses): char = presses[index] if char == 'U': floor += 1 elif char == 'D': floor -= 1 if floor == 2: print(index + 1) break index += 1 Based on the above data answer the subsequent questions.
What is the given code snippet printing?
It prints the number of button presses after which you reach the floor 2 for the first time.
It prints the number of times you cross the floor 2.
It prints the final floor level after all the button presses.
None of these.