Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (anonymous):

psy4 part b. how do you create a while loop that runs until it reaches the last item in a list? i'm trying to run through the second problem in problem set 4 and need to create a condition for looping through the list of growth rates. am i thinking about this correctly or is there a better set of criteria for the while loop? here's my code so far: http://dpaste.com/546068/

OpenStudy (anonymous):

I used a for loop instead of a while loop like this: for year in range(1,len(growthRates)+1): that will get the length of the growthRates list and I add one more to include the last element. Hope that helps!

OpenStudy (anonymous):

I used a for loop too. If you really want to use while you can use while(i<len(glist)) (where glist is the list you want to run through. Then use glist[i] within the loop to use each element (if you want too). However, for loop is the easiest way to go.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!