Write a function count_clear (state) that takes a state of the cargo terminal, a
ID: 3587888 • Letter: W
Question
Write a function count_clear (state) that takes a state of the cargo terminal, and returns an integer count of the number of containers in the given state that are currently clear (i.e., have nothing stacked on top of them) Notes and assumptions: Note: The ground is not a container, so it doesn't count. . You can assume there are no duplicates. >>> count-clear ( [ [ ' c1' , ' c3' ] , e2 ' , ' ground ' ] , [ ' c3 ' , ' ground' ] ] ) 2 >>> count-clear ( [ [ ' c1' , ' c3' ] , [ ' c3 ' , ' c2' ] , [ ' c2' , ' ground ' ] ] ) 1 >count.clear (II'c4', 'ground'], ['c5', 'ground'], ['c6', 'ground']1)Explanation / Answer
def count_clear(state):
count = 0
for i in range(len(state)):
if len(state[i]) == 2:
if state[i][1] == "ground" :
count = count + 1
return count
print(count_clear([['c1','c3'],['c2','ground'],['c3','ground']]))
print(count_clear([['c1','c3'],['c3','c2'],['c2','ground']]))
print(count_clear([['c4','ground'],['c5','ground'],['c6','ground']]))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.