S
9

Just got my first Python script to run without errors after two days of trying

I was trying to make a simple program that asks for your name and then prints a greeting. For two days straight, it kept throwing a 'NameError' because I kept messing up the variable. I finally realized I was trying to use the variable before I actually defined it. Fixed that one line and it worked perfectly. Has anyone else gotten stuck on something that simple for way too long?
3 comments

Log in to join the discussion

Log In
3 Comments
irismartinez
That "using the variable before defining it" thing is so common. I read once that it's one of the top five beginner mistakes in Python.
4
the_adam
the_adam5d ago
Totally see that all the time. Watched a friend try to print a username before getting it from input, just got a NameError. Another classic is checking if a variable equals something in an if-statement, but you spelled the variable wrong earlier. It's such a simple fix once you spot it, but it trips everyone up at first.
4
the_christopher
Remember when you try to call a function but forget the parentheses? You just type the function name and stare at the screen when it says function object isn't callable. Or mixing up single equals and double equals in a condition, that's a classic. Your brain just goes on autopilot and you miss the tiny detail. It's always the small syntax that locks you up for hours.
2