Topic awaiting preservation: Finding Fibonacci numbers? (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: Alderaan |
posted 10-20-2004 03:58
A bonus question on my homework is to modify one question (where we print out the first 50 Fibonacci #s) so that the user inputs a number through a form, the program checks to see if its a Fibonacci #, if it displays the form again and tells the user which is the closest Fib. #. If it does, it prints out the sequence starting with that number. |
Paranoid (IV) Inmate From: Back in West Texas... How disappointing |
posted 10-20-2004 17:29
You should be able to just take the input, set that as the end of your loop, calculate the Fibonacci sequence (series?) up to that number, then have a test whether the last number you calculated was equal to the limit or less than. If it's less than, find out if it's closer than the next number. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 10-20-2004 23:32
quote:
|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
posted 10-21-2004 05:42
I liked this question so I programmed it. 36 easily readable lines of python code. Ever since I started writing scripts in python programming has become a whole lot more fun. |
Nervous Wreck (II) Inmate From: Alderaan |
posted 10-21-2004 19:25
Since, the assignment isn't due for some time I put it off and went back to it two days ago with a fresh start. I definitely was making it more complicated then necessary. code: $number = 0;
|
Nervous Wreck (II) Inmate From: Alderaan |
posted 10-21-2004 19:38
Actually, one question I have is how do I pass variables back to the same page? I'm using $_POST to pass variables. If the # the user enters on the original form isn't in the sequence I'm to display the message about which # is closest and then provide a form so the user can re-enter their #s. Should I still be using $_POST for this? |
Paranoid (IV) Mad Scientist with Finglongers From: Germany |
posted 10-21-2004 21:38
post is fine. I presume you want to 're-pre-fill-out' the fields? just print a value attribute to them, and have the user resubmit the form. |
Paranoid (IV) Inmate From: Back in West Texas... How disappointing |
posted 10-21-2004 21:51
Sorry about that. I was trying to say what Slime said, but I didn't word it very clearly I guess. Thanks for clarifying for me Slime. |