| | |
Beginners Problem
![]() |
•
•
•
•
ok this is what i have;
from math import *
x=input("What value will you give x?:")
n=input("Please set a maximium amount of iterations?:")
for i in range (n):
x = x - ((x-cos(x))/(1 + sin(x)))
break
y =x
if (y-x) <= 10**-8:
print y
elif (y-x) > 10**-8:
continue
still not working..advice??
[code=python]
# Code in here
[/code]
Just to be nice I'll wrap your code for you:
python Syntax (Toggle Plain Text)
from math import * x=input("What value will you give x?:") n=input("Please set a maximium amount of iterations?:") for i in range (n): x = x - ((x-cos(x))/(1 + sin(x))) break y =x if (y-x) <= 10**-8: print y elif (y-x) > 10**-8: continue
So first thing: remove the break and the continue statements.
Next,
y = x should be assigned at the end of your loop.That should get you a little closer
Python Syntax (Toggle Plain Text)
x = initial_value x_last = x threshold = minimum_change MAXITER = maximum_iterations_desired iterations = 0 while iterations < MAXITER and x - x_last > threshold: x_last = x x = iterate(x) # x now holds your result
Using
break and continue is overcomplicating things, IMO. Last edited by Nuez_Jr; Jan 6th, 2009 at 3:15 pm. Reason: Apparently [icode] doesn't have a language parameter ; )
![]() |
Similar Threads
- Good Book for beginners in C# (C#)
- Class Module VB.net Problem (VB.NET)
- help w/ problem (C++)
- vb.net NEWBIE!! Triangle problem!! (VB.NET)
- Symbian help (C++)
- BlueJ problem (Java)
- Prog to list ASCII codes (beginners' stuff) (C)
Other Threads in the Python Forum
- Previous Thread: Avoiding multiple openings of the same file in python
- Next Thread: urllib - check if web page exists
| Thread Tools | Search this Thread |
address advanced aliased anydbm bash beginner bits calling casino changecolor clear conversion convert corners count csv cturtle cursor curves definedlines dictionary digital dynamic dynamically events examples excel external file float format frange function gui handling hints homework i/o iframe import input java line linux list lists loan loop matching mouse multiple number numbers output parsing path port prime programming projects py py2exe pygame python random rational raw_input recursion recursive scrolledtext searchingfile shebang signal singleton string strings subprocess table tails terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode urllib urllib2 valueerror variable web-scrape whileloop word wxpython






