Variable not defined? Programming Software Development by hovestar …CODE] What value would you like to find if the collatz works for below?6 Traceback (most recent call last): …("What value would you like to find if the collatz works for below?")) pre = 1 count = 0 value…elif value < 1: print "This value defies the collatz conjecture:", pre else: print pre, "has", … Re: Variable not defined? Programming Software Development by TrustyTony …moving print out of calculating function...: [CODE]def collatz(): for current in range(1,int(raw_input("…What now would you like to find if the collatz works for below? "))+1): print "%…i has %i to complete the collatz" % (current, step_counter(current, current, 0)) def step_counter… Re: Variable not defined? Programming Software Development by hovestar …("What value would you like to find if the collatz works for below? ")) while finder > pre: value = pre… Help with loops and when they end? for a newbie? Programming Software Development by sammyboy289 … how long it takes to get to 1, using the 'Collatz Problem' i take the value of n to be inside… Re: Projects for the Beginner Programming Software Development by vegaseat Explore Collatz numbers (the 3n+1 problem, L. Collatz in 1937) http://mathworld.wolfram.com/CollatzProblem.html Take any number, if even divide it by 2, if odd multiply it by 3 and add one, should converge to 2 (ultimately to 1). For instance starting with 7 ... 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 Re: Code Snippet Ideas Programming Software Development by vegaseat Explore Collatz numbers (also called the 3n+1 problem, L. Collatz in 1937): Take any number, if even divide it by 2, if odd multiply it by 3 and add one, and so on, should converge to 2 (ultimately to 1). Re: An introduction to algorithms Programming Computer Science by morten42 … problem is also known as the 3n+1 problem, the Collatz algorithm, and the Syracuse problem. === Greatest common divisor is for… Re: while loops,even and odd numbers and counting loops. Programming Software Development by Nick Evan It's called the "Collatz Conjecture". Things I spot: 1. [code] void errorCheck(int … Re: Variable not defined? Programming Software Development by TrustyTony counter has not local parameter or variable named value. It is local because it is used at left side of assignement in function. You probably should have the variable as parameter of recusive function counter. You will hit the limit of recursion pretty soon so you better use regular loop. Re: Variable not defined? Programming Software Development by woooee Passing parameters to a function [url]http://www.tutorialspoint.com/python/python_functions.htm[/url] Re: Variable not defined? Programming Software Development by hovestar I had to define it globally thanks for your help though. Re: Variable not defined? Programming Software Development by TrustyTony And if you think little where start parameter is used, it is not, and can be removed. Re: Help with loops and when they end? for a newbie? Programming Software Development by Stefano Mtangoo So in summary (for lazy to read like me), what is the issue? Doesn't work as intended or throws exception? What is the error? Re: Help with loops and when they end? for a newbie? Programming Software Development by sammyboy289 The error is, my b statement doesn't keep resetting which it should, and my list continues even once its reached 1, which i dont understand why :( also, im not sure if my else: statement is in the right place. Sorry i write a lot Re: Help with loops and when they end? for a newbie? Programming Software Development by nezachem Let's see what happens when n is 2. Your first if condition is true, you divide n by 2 and it becomes 1. Now your second if condition is also true! Welcome to the infinite loop. Re: Help with loops and when they end? for a newbie? Programming Software Development by sammyboy289 should it loop, i didn't think it would, because thats while n != 1, so it should stop that loop and move onto the else: statement, or is that incorrect? i can't quite work out, how to make 2 loops, and when one ends, go to the next statement. That's the main problem im dealing with, sorry if im explaining wrong or being really useless Re: Help with loops and when they end? for a newbie? Programming Software Development by Ene Uran Shorten the list and add a temporary print for testing. See what that will do for you: [code]# shorten list for test a = range(1, 10) b = [] d = 0 for n in a: while n != 1: if n % 2 == 0: b.append(n) n = n/2 elif n % 2 != 0: b.append(n) n = n*3 + 1 else: b.append(n) … Re: Help with loops and when they end? for a newbie? Programming Software Development by nezachem At run time, things happen one step at a time. Let's trace the execution of your program with n being 2 [CODE]while n != 1: # Python checks that n is not 1, and enters a loop if n % 2 == 0: # Python checks that n is even and enters the if-clause ... n = n/2 # [B]n becomes 1[/B] if n % 2 != 0: # Remember,… Re: Help with loops and when they end? for a newbie? Programming Software Development by sammyboy289 wow, that worked, thank you so much, if its not too much to ask, do you mind saying how you changed it, and what it does?, because i notice the elif: statement which im not good with, and one question about the last part, as i will only want one resut to show, will i need to change [CODE]# print b, d, len(b) if len(b) > d: d = len(b) b = [][/… Re: Help with loops and when they end? for a newbie? Programming Software Development by sammyboy289 ok, i want to thank nezachem for showing why it went wrong, and i want to thankEne Uran as to showing me what was the way to fix it. I have finally sorted out my code, and i am very thankful to all of you for helping me. You have helped me understand and hopefully i can become better at python :D