# Solutions

## Questions

2. Answer: The if statement is inside another if loop.

## Exercises

1. Answer: There will be an error and the script will not run if lines are not properly indented.
2. Answer: The index value can be placed inside a loop with a + / - used to increase or decrease the index value.  Incrementally changing the index value will move through the list items assigned to the corresponding index values.
3. Answer: The pushbutton states are read, 0 or 1, and that information is then passed to other components via write statements to dictate their behavior. Ex: read_digital and write_digital.

## Projects

1. Solution.

```# rotate_leds_leds_off

from microbit import *

pin = [pin13, pin14, pin15]
time = [200, 200, 200]
index = 0
state9 = 0
state6 = 0

display.off()
pin9.set_pull(pin9.NO_PULL)
pin6.set_pull(pin6.NO_PULL)

while True:

if state9 is 1:
index = index + 1
if index > 2:
index = 0
pin[index].write_digital(1)
sleep(time[index])
pin[index].write_digital(0)

if state6 is 1:
index = index - 1
if index < 0:
index = 2
pin[index].write_digital(1)
sleep(time[index])
pin[index].write_digital(0)```

2. Solution.

```#project_solution

from microbit import *

pin = [pin13, pin14, pin15]
time = [1500, 1000, 500]
index = 0
state9 = 0
state6 = 0

display.off()
pin9.set_pull(pin9.NO_PULL)
pin6.set_pull(pin6.NO_PULL)

while True:

if state9 is 1:
index = index + 1
if index > 2:
index = 0
pin[index].write_digital(1)
sleep(time[index])
pin[index].write_digital(0)
sleep(time[index])

if state6 is 1:
index = index - 1
if index < 0:
index = 2

pin[index].write_digital(1)
sleep(time[index])
pin[index].write_digital(0)
sleep(time[index])```

3: Solution.

```# buttons_with_leds_and_zip

from microbit import *

pin_list = [pin13, pin14, pin15]
time_list = [500, 1000, 1500]
state9 = 0

display.off()
pin9.set_pull(pin9.NO_PULL)

while True: