Challenge - 5 Problems
Naming Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of variable naming with underscores
What is the output of this code snippet?
Python
my_var = 10 _myVar = 20 print(my_var + _myVar)
Attempts:
2 left
💡 Hint
Remember that variables starting with underscore are valid names.
✗ Incorrect
Both variables are valid and hold integer values. Adding them results in 30.
❓ Predict Output
intermediate2:00remaining
Output with invalid variable name
What error does this code raise?
Python
2nd_var = 5 print(2nd_var)
Attempts:
2 left
💡 Hint
Variable names cannot start with a number.
✗ Incorrect
Variable names cannot begin with digits, so this causes a SyntaxError.
❓ Predict Output
advanced2:00remaining
Output of variable naming with reserved keywords
What error does this code produce?
Python
class = 10 print(class)
Attempts:
2 left
💡 Hint
Reserved keywords cannot be used as variable names.
✗ Incorrect
Using 'class' as a variable name is invalid and causes a SyntaxError.
❓ Predict Output
advanced2:00remaining
Output of variable naming with case sensitivity
What is the output of this code?
Python
Var = 5 var = 10 print(Var + var)
Attempts:
2 left
💡 Hint
Python variable names are case sensitive.
✗ Incorrect
Var and var are two different variables holding 5 and 10 respectively. Their sum is 15.
🧠 Conceptual
expert2:00remaining
Identify the valid variable names
Which of the following variable names are valid in Python? Select the one that is NOT valid.
Attempts:
2 left
💡 Hint
Variable names cannot contain hyphens.
✗ Incorrect
Variable names cannot have hyphens (-). Option D is invalid because of the hyphen.