Code:#!/usr/local/bin/python #fibonacci print "this fibonaci" deret = raw_input("input your rows = ") a = 0 b = 1 while a < deret : c = a + b print c, a = b b = c a = a + 1
hey this dont work properly, can anybody correct this c0de.....
python uses indentation to control loops. Your while loop doesn't contain anything.
while a < deret
....
....
a = a+1
that loop control, is wrong control
Everything that should be in your while loop needs to be tabbed in once. Python uses whitespace to indicate loops. As is, your while loop is an infinite loop that does nothing.
There's a couple of problems with your code actually. The first and most obvious is that the loop needs to be indented. As it is python considers the loop to be empty and thus the code below never runs as nothing happens within the loop to change the value of a or deret. the code for your loop should look like this
However, even with this sorted your loop will never end. The logic statement for the while loop is comparing a, an integer, to deret, a string. Python considers strings to be greater than integers so a < deret will always return true.Code:while a < deret: c = a + b print c, a = b b = c a = a + 1
you need to convert deret to an interger
As an aside, what is your code intended to do? Do you want to print a fibonacci sequence with terms less than the user input? You may want to check your logic if this is what you're tring to do.deret = raw_input("input your rows = ")
deret = int(deret)
Instead of using the int(raw_input()) i believe you should use the input() function and i don't understand why you added a (,) after the print. Besides there's no need for the c variable.
Your code should be more less like this :
Code:a, b, choice = 0, 1, input('Some text here.') while a < choice: a, b = a + b, a if a < choice: print a
Last edited by psam; 06-23-2009 at 04:48 AM.
ok thanks .....i will try n correct my script
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks