Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (anonymous):

Infinite loop problems. Used this code: To write an infinite loop, use True as the condition: while (True): i = getInput() print("input is",i) process(i) Got this error: Traceback (most recent call last): File "/Users/nfsiddiqui/Documents/whileloop.py", line 18, in i = getInput() NameError: name 'getInput' is not defined Using: Python 3.3.2 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Was going through this: http://beastie.cs.ua.edu/cs150/book/index_14.html Please advise on what the error is.

OpenStudy (e.mccormick):

It is saying that you never defined a function called getInput(). That example is using a non-standard function.

OpenStudy (e.mccormick):

As a standard function, if it was for user input, you would use raw_input() or input() in python2.x, and input() or eval(input()) in python3.x. For the example listed, I would do something different. The goal is to show you an infinite loop, which is a BAD thing to make. An easy one is this: i=0 while (True): i = i+1 print(i) Note, the above code is python 3.x code. I can tell because of the () around what you are printing. In 2.x, it woull be slightly different.

OpenStudy (e.mccormick):

And you use control-c to stop it when you get tired of seeing numbers whiz by.

OpenStudy (anonymous):

Thanks, just tried your infinite loop and it worked. The commands get input, raw input, eval input...do they change every time a new version of python is released? Or am I not understanding what they are for?

OpenStudy (e.mccormick):

2.x has flaws. 3.x is a major overhaul, but they don't expect full implementation for about another year or two. So at this point 2.x is still more popular, but 3.x is very popular. They gave a 5 year plan for the change over, and it is 4 years in....

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!