Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Finding the root of a function.

I'm working on a project for school and I've come up with a bit of Pseudocode for my algorithm and was wondering if I could get a few tips to help get this built properly in Python.

Input function f(x) and save as var f Assign value of 0 to i assign value of 1 to n while i != f while i < f i + n n / 10 = n

while i > f
    i - n
n / 10 = n

while i < f
    i + n

if i = f: print "Root equals "+ i

else:
    loop

Things to fix

  • possibility of infinite loop
  • loop while statements until i = f
  • Make code into real python code that will actually run.
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Sorry. I'm confused. Are you trying to find the root of a function? Ie are you trying to factor a quadratic equation? Or are you trying to find the square root of a number? Because the title says "foot" of a function, but I'm guessing that's a typo.

2 Answers

Haha. Yes the root. (Evil mobile device keyboards)

My project it to find the root of a function (f(x)=0) by moving sequentially from zero until I pass the root. Then changing direction and moving at 1/10 of that rate and repeating up I arrive at that number.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Are you required to use that algorithm or are you allowed to use Newton's? And I'm assuming we're talking any positive number and not dealing with imaginary numbers here.

They want me to use that algorithm. Visualizing following along the x axis to find where the line crosses y0.