Infinite loop problems.
Used this code:
To write an infinite loop, use True as the condition:
i = getInput()
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
[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.
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
It is saying that you never defined a function called getInput(). That example is using a non-standard function.
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 = i+1
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.
And you use control-c to stop it when you get tired of seeing numbers whiz by.
Not the answer you are looking for? Search for more explanations.
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?
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....