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.
That should do it.Code:def iterate(x, y, iterations): for unusedvariable in range(iterations): x = (x + y) * (x + y) return x
Wow I changed my sig!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks