There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
File “script.py”, line 1, in
print(score)
NameError: name ‘score’ is not defined
I was just wondering how could the computer identify this case as a NameError instead of a SyntaxError(It can also be interpreted as ‘score’ is a string but quotation mark is missing).
It isn’t really relevant for the lesson. They already provide the answer to the question which is A(a)/option 1, Fresca.
You are supposed to simply assign the variable ‘option3’ to any answer you want, since that’s one of the name errors you have to debug. Yoohoo, water, orange juice, it doesn’t matter. The code will use ‘A’ (option1) as the answer regardless of what beverage you assign option3 to.
Hope it makes sense.
You have prolly figured this out by now but I’m answering, nonetheless, for anyone who might be confused in the future.
In this program there are two name errors, one is option3 variable is not defined and other one is score variable was incorrectly typed in line 19. We have two solutions here, either option3 variable can be defined or print statement in line 13 can be removed.
I agree. I knew there was an error that option3 was not defined yet. I was looking for something else in the code which would hint to what option3’s value should have been. I would have never guessed that I was just supposed to just put anything that I wanted there.
Hi, why it still gives me “#2: There’s a misspelled variable name somewhere in the program.” ?
I fixed option3 by defining it above, and scor+ in score = 100 in line 20. But it still gives me an error.
Old post, but in case anyone else is wondering in the future…
It knows that it’s a name error because without the quotations, Python interprets score as a variable. Any variable related misspellings and undefined variables would throw a name error.
Syntax error is more for when you have errors in spelling out commands and keywords in the program, like a punctuation that doesn’t belong or missing paranthesis, or partially missing quotations as you mentioned. It doesn’t have anything to do with a variable.
By the way, if it’s a string that you are typing, Python would never throw an error based on misspelling. It’s not a spellchecker and strings can be whatever sequence of characters you want.
The += notation is an addition assignment used to add the value to the existing variable. So in this case it adds 100 to the score. Removing it would solve the name error (since no misspelling of the variable exists) but you are also removing a functionality from the program.