Python Basics Worksheet (With Answers at End of Each Part)
Part 1: Variable Names Rules
Q1: Choose the correct variable name (✔) and incorrect (✖):
1. name ______
2. my_name ______
3. 2name ______
4. student-name ______
5. age1 ______
6. class ______
Q2: Fix the wrong variable names:
1. 1student = "Ali" → __________
2. my-name = 10 → __________
3. class = "Grade 8" → __________
Answers (Part 1)
Q1:
1. ✔
2. ✔
3. ✖
4. ✖
5. ✔
6. ✖
Q2:
1. student1 = "Ali"
2. my_name = 10
3. class_name = "Grade 8"
Part 2: NameError
Q3:
print(name)
Answer: __________
Q4:
age = 15
print(ag)
- What is the error? __________
- How to fix it? __________
Answers (Part 2)
Q3: NameError because variable not defined
Q4: NameError, fix: change ag to age
Part 3: SyntaxError
Q5:
print("Hello)
Fix: __________
Q6:
if 5 > 2
print("Yes")
Fix: __________
Answers (Part 3)
Q5: print("Hello")
Q6: if 5 > 2:
Part 4: Multiple Choice
Q7: Which is valid?
a) my-name
b) my_name
c) 1name
d) @name
Q8:
print(x)
Type of error?
a) SyntaxError
b) NameError
c) TypeError
Answers (Part 4)
Q7: b
Q8: b
Part 5: Complete the Code
Q9:
name = "Ali"
print(_______)
Q10:
Age = 14
print(age)
Fix: __________
Answers (Part 5)
Q9: print(name)
Q10: print(Age)
Bonus:
Write code to store your name and print it.
Answer:
student_name = "Hadeer"
print(student_name)