this is my code for now:
Please tell me if the code above shows up I was having trouble with adding screenshots. The goal of my code is for it to scan the 2D list(parking lot) and find a open parking spot which is 1:
0 = Aisle or road that can be traveled
1 = Filled parking spot
2 = Available parking spot
I need to use a conditional and print the variable open parking spots at the end.
Here are the reqs:
- Create nested while loops and a conditional that scans the mapped parking lot list for open spots.
- Use a conditional statement to tell the program it should increment the open_spots variable when it finds an available parking spot.
- Include print statement at the end of your program to display the total number of available parking spots on the SDV’s screen. For example: The number of available parking spots is …
Thank you!
I made a mistake “Please tell me if the code above shows up I was having trouble with adding screenshots. The goal of my code is for it to scan the 2D list(parking lot) and find a open parking spot which is 1:” ITS NOT 1 ITS 2 sorry…
This is the code I have after waiting for it to get approved can anyone help me get it converted into blocks?
vexcode_brain_precision = 0
col = 0
row = 0
open_spots = 0
parking_lot = [[0 for y in range(5)] for x in range(5)]
def when_started1():
global col, row, open_spots, parking_lot, vexcode_brain_precision
col = 0
row = 0
open_spots = 0
parking_lot = [
[0, 0, 0, 0, 0],
[0, 2, 1, 1, 2],
[0, 2, 2, 1, 2],
[0, 0, 0, 0, 0],
[0, 1, 2, 2, 1]
]
while row < 5:
col = 0
while col < 5:
if parking_lot[row][col] == 2:
open_spots += 1
elif parking_lot[row][col] == 1:
open_spots -= 1
col += 1
row += 1
brain.print("The amount of available parking spots are ")
brain.print(open_spots, precision=vexcode_brain_precision)
vr_thread(when_started1)
edit: code tags added by mods, please remember to use them.