Python Basics Homework
Part A – Variables & Basic Math in Python
1. Identify valid variable names
For each of these, say if it’s a valid Python variable name or invalid. If invalid, explain why.
a. age
b. 1st_number
c. total_sum
d. my-name
e. pi_value
f. class
2. Fill in the blanks – Creating variables
Write Python code to:
a. Store your name in a variable called student_name.
b. Store your age in a variable called age.
c. Store the result of 5 + 8 in a variable called result.
d. Change the value of age to be 1 year older.
3. Predict the output – Basic math and variables
a.
x = 10
y=3
print(x + y)
print(x - y)
print(x * y)
b.
a = 15
b=4
print(a // b)
print(a % b)
c.
num = 7
num = num + 3
print(num)
num = num * 2
print(num)
4. Write small programs
a. Program asking for age, storing it, and printing it.
b. Program storing a = 8, b = 2 and printing arithmetic results.
Part B – Lists and Tuples (Theory Questions)
5. Concept questions
a. What is a list in Python?
b. What is a tuple in Python?
c. One similarity between lists and tuples.
d. One difference between lists and tuples.
6. True or False
a. A list can change.
b. A tuple can change.
c. Lists use [].
d. Tuples use {}.
e. Both lists and tuples use indexing.
7. What is the output?
a.
numbers = [2, 4, 6, 8]
print(numbers[0])
print(numbers[2])
b.
fruits = ("apple", "banana", "mango")
print(fruits[1])
c. Length of ["red", "blue", "green", "yellow"]
8. Short written answers
a. Why use a tuple?
b. Example of something stored in a list.
c. Example of something that should not change and fits a tuple.
Part C – Basic CLI Commands
9. Match the command
1. mkdir
2. cd
3. dir
a. Show files/folders.
b. Change directory.
c. Create folder.
10. Fill in the blanks
a. _______ projects
b. _______ homework
c. _______
11. CLI scenarios
a. Create folder Python.
b. Enter Python folder.
c. Show contents of Python folder.
d. Go back one level.