A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

could someone help me with the concept behind iteration in python

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

    Iteration is the process of performing an action until a certain test is met. For example if you are driving to Grandma's house and she lives at exit 10 then you evaluate each exit to see if it is exit 10 if it not then you continue driving and test the next exit. Here is a quick example using a "while" statement. The interation occurs as I increase the exit until it equals 10 #Are we there yet/ exit = 5 #set starting exit while exit <> 10: #test for exit 10, while exit DOES NOT EQUAL 10 print "Only at exit ", exit, " keep on going" exit = exit +1 #drive to the next exit. #run test again #when test is true print "We are at exit ", exit, "I hope Grandma is home" #This prints when we get to exit 10 #end You can copy this program, save it and run it to see what it outputs./ The ouput should look like this: Only at exit 5 keep on going Only at exit 6 keep on going Only at exit 7 keep on going Only at exit 8 keep on going Only at exit 9 keep on going We are at exit 10 I hope Grandma is home

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

    So basically iterative is using the while sumthing sumthing: do this and recursive is for each of these: do this ? Or have I misunderstood?

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

    No wait, the recursive one modifies what we are working on right? So for problem set three it would change the target string...

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

    thank you both for the help

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

    No no no - I'm not helpful. I'm just trying to understand it too. After I posted this I found and read the Wikipedia entry on recursion: http://en.wikipedia.org/wiki/Recursion_%28computer_science%29 It helped me heaps, especially the bit about the Fibonacci function where it's written in both pseudocode and python. So for iterative code you use for: or while: but for recursive you call the function within the function using things like if: elif: and else:

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

    ok well the wikipedia info looks good and rwmuller did a great job

  7. 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.