Python Stuck on Continue Statement: Solving a Python Coding Problem

AI Thread Summary
The discussion revolves around a user's struggle with a Python script that utilizes the continue statement. The user is encountering a NameError when running the script, specifically when inputting a single character. The issue arises from the use of the input function, which in Python 3 expects user input as a string but is being interpreted incorrectly due to the way the input is processed. The user expresses frustration after spending significant time trying to resolve the issue and seeks assistance. A helpful response points out the mistake, clarifying that the input should be treated as a string rather than a variable. The user acknowledges the oversight and appreciates the guidance, highlighting the common challenges faced by beginners in programming.
mockingbird
Messages
3
Reaction score
0
I Have been using A Byte of Python, and I am now stuck on the Continue Statement. Here is my code.

#!/usr/bin/python
#Filename: continue1.py

while True:
s = input('Enter something : ')
if s == 'quit':
break
if len(s) < 3:
print('Too Small')
continue
print('Input is of sufficient Length')
#Do other kinds of Processing here...

I keep getting this...

andrew@andrew-laptop:~$ python continue1.py
Enter something : a
Traceback (most recent call last):
File "continue1.py", line 5, in <module>
s = input('Enter something : ')
File "<string>", line 1, in <module>
NameError: name 'a' is not defined

I am completely new at this, but I have 1. Spent more than two hours trying to figure this out. 2. Looked online for longer than an hour to find an example of what I have done wrong. 3. Stared at this problem until my eyes have bled.
I hope someone can/will help me figure this out. I am using gedit that came with my version of Ubuntu. I don't know if that will change anything.
 
Technology news on Phys.org


Well my code didn't come out properly, here is the link that I am imitating. The Break Statement and the Continue Statement are the ones that aren't working.

http://www.swaroopch.com/notes/Python_en:Control_Flow

I am pretty sure that I am putting everything in the way he is telling me.
 
Last edited by a moderator:


Hey! Thanks man, I glad you pointed that out to me. Like I said, was probably a really easy, simple, stupid fix. I feel embarassed now, but like I said I was copying his code, and couldn't figure anything out. Really Appreciate you helping a Noob out.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top