Q13Comprehension2 Marks24 Dec 2023
Passage
Based on the above data, answer the given subquestions.
You are inside the lift of a building. There are 10 levels in the building:
[-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
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. Now study the code given below:
```
# presses contains the sequence of button presses made by you
presses = "UUUUDDDDD"
floor = 0
index = 0
while index < len(presses):
char = presses[index]
if char == 'U':
floor += 1
elif char == 'D':
floor -= 1
if floor == -1:
print(index + 1)
break
index += 1
```
What is the output of this snippet of code?
Press Enter to check.