Gallery
Tony's Grossery
Share
Explore
Tony's Grossery

icon picker
Stage 2

2. Look for the problem: inefficiency

The inefficiency is that it takes so many statements to display the products!
Tony’s Grossery is a small store.
How about a big supermarket? They might have 25,000 products so your program would have 25,000 lines just to display all the products!

3. fixing the inefficiency

hint
the task suggests you add a loop
you are told to check out the CodeClips
there are 2 interesting clips:
size of an array
arraySize = len(nameOfArray)
the length of an array means the number of elements
an array of length 10 would have element positions 0-9
the first element is 0, the last element is 9
traversing an array
# prints out each element of array
for i in range (0, len(nameOfArray), 1):
print(nameOfArray[i])
# end of loop
You should now
think carefully how you can use the loop code
what changes you will make
carefully go ahead and make the changes
Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.