A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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/

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.