Format Challenges and Solutions in For Loops in Episode 12 - Possible solution for Identifying Variable Name Errors
Solution:
The first error is "NameError: name 'Number' is not defined". This variable error is a misspelled variable. The variable was defined with a lower case (number) but used later with a different spelling (Number).
The second error is "NameError: name 'message' is not defined". This variable error is a variable that should have been defined but was not. The script uses the variable message to build a message by appending strings to the original message. The variable must first be defined with an original message, in this case, it is an empty string.
The third error is "NameError: name 'a' is not defined". The variable error is a string with no quotes. The "a" is currently used as a variable in the script. However, the goal of the script is to add the letter 'a' as a string. Adding quotes around the "a" will solve the variable error.
The solution without any variable name errors is:
message = ""
for number in range(10): # use a if the number is a multiple of 3, otherwise use b if (number % 3) == 0: message = message + "a" else: message = message + "b" print(message)