mardi 7 juillet 2020

Write a function that returns the coordinates of an available spot for a vehicle or returns False if there is no spot

There are three kinds of possible vehicles: regular cars, small cars, and motorcycles.

Regular cars can only park in R spots. Small cars can park in R or S spots. Motorcycles can park in R, S, or M spots.

Also uppercase indicates that the spot is available and lowercase indicates that the spot is taken

spots = [
    ['s', 's', 's', 's', 's', 's'],
    ['s', 'm', 's', 'S', 'r', 's'],
    ['s', 'm', 's', 'S', 'r', 's'],
    ['S', 'r', 's', 'm', 'r', 's'],
    ['S', 'r', 's', 'm', 'R', 's'],
    ['S', 'r', 'S', 'M', 'm', 'S']
  ]

So i am guessing I have to loop over the spots list to start off, so this is what I have:

for i in spots:
        if not i.isupper():
            return False 
    return True

I keep getting the list has no attribute 'isupper' error which I understand why but I don't know how to fix it, let alone move forward with the rest of the problem. Any help is greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire