Closed Thread
Results 1 to 2 of 2

Thread: Need to create simple iterative program

  1. #1
    dmehling is offline Newbie
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Need to create simple iterative program

    I am a novice to Python and I'm trying to create a simple program to perform an iterative function. I want the program to take a number (let's call it x), add a number, and square the result. Then, I want to replace x with the result and perform the addition and squaring operations once again. I want to keep feeding that new result back into the equation. I need to know how I can do this and how I tell the program how many times I want it to iterate. I'm using version 3.1.1.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Need to create simple iterative program

    Code:
    def iterate(x, y, iterations):
        for unusedvariable in range(iterations):
            x = (x + y) * (x + y)
    
        return x
    That should do it.
    Wow I changed my sig!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 10-13-2011, 08:52 PM
  2. Beginner A drop-dead simple way to create a plugin interface
    By Grue in forum CSharp Tutorials
    Replies: 1
    Last Post: 08-18-2011, 07:36 PM
  3. Create Simple Back Up Application
    By R8ter63 in forum Visual Basic Programming
    Replies: 3
    Last Post: 01-22-2011, 05:03 PM
  4. How to create a simple egg timer
    By Vswe in forum Visual Basic Tutorials
    Replies: 8
    Last Post: 09-19-2010, 05:26 AM
  5. create simple key logger with C++
    By vaheb in forum C and C++
    Replies: 5
    Last Post: 08-20-2010, 04:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts