Our Office
Ernakulam, Kottayam
Email Us
linusfacts@gmail.com
Call Us
+91 9544409513
1. Create a list named matrix that contains:<br>[1, 2, 3],<br>[4, 5, 6],<br>[7, 8, 9]<br>2. Print the element 8.<br>3. Print the second row of the matrix, i.e. 4, 5 and 6.<br>4. Print the third column of the matrix, i.e. 3, 6 and 9.<br>5. Print the diagonal of the matrix, i.e., 1, 5 and 9. 1. Create a list named first_list that contains 0, 1, 2, 3 and 4.<br>2. Create a new list named copy_list by doing copy_list = first_list.<br>3. Modify the last element of copy_list.<br>4. Print first_list.<br>5. What happened ?<br>6. Find a way to correctly copy the first_list. 1. Create a list named values that contains 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10.<br>2. Slice the list such that you get every second element starting from the end, but not<br>including the last element.<br>3. Print the result (it should be 9, 7, 5, 3, 1). 1. Create a tuple that contains 0, 0, 1, 0, 1, and 1<br>2. Count the number of 0 using a method.<br>3. Find the index of the first 1 using a method.<br>4. Delete the tuple.<br>Tips: To delete a tuple, you could use del followed by the tuple name. 1. Create a list named fruits containing the following items: "apple", "banana", "cherry".<br>2. Print the list to ensure it has been created correctly.<br>3. Create a tuple named vegetables containing the items: "carrot", "broccoli", "lettuce".<br>4. Print the tuple. 1. Given a list named colors that contains "red", "blue", "green", "yellow" and "pink"<br>2. Print the second and fourth items from the list.<br>3. Given the tuple named grades that contains "A", "B", "C", "D" and "F"<br>4. Print the first and last items from the tuple.

QUESTIONS

1. Create a list named matrix that contains:
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
2. Print the element 8.
3. Print the second row of the matrix, i.e. 4, 5 and 6.
4. Print the third column of the matrix, i.e. 3, 6 and 9.
5. Print the diagonal of the matrix, i.e., 1, 5 and 9.

Right Answer:


# Step 1
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
# Step 2
print(matrix[2][1]) # Output: 8
# Step 3
print(matrix[1]) # Output: [4, 5, 6]
# Step 4
third_column = [row[2] for row in matrix]
print(third_column) # Output: [3, 6, 9]
# Step 5
diagonal = [matrix[i][i] for i in range(len(matrix))]
print(diagonal) # Output: [1, 5, 9]

1. Create a list named first_list that contains 0, 1, 2, 3 and 4.
2. Create a new list named copy_list by doing copy_list = first_list.
3. Modify the last element of copy_list.
4. Print first_list.
5. What happened ?
6. Find a way to correctly copy the first_list.

Right Answer:


# Step 1
first_list = [0, 1, 2, 3, 4]
# Step 2
copy_list = first_list # This is an assignment, not a true copy
# Step 3
copy_list[-1] = 9 # Modify the last element of copy_list
# Step 4
print(first_list) # Output: [0, 1, 2, 3, 9]
# Step 5 - Explanation
# Both `first_list` and `copy_list` refer to the same list in memory, so changes to one affect the other.
# Step 6 - Correct way to copy the list
copy_list = first_list.copy() # Use the .copy() method for a true copy
# Verifying by modifying copy_list again
copy_list[-1] = 8
print(first_list) # Output: [0, 1, 2, 3, 9] (no change in first_list)
print(copy_list) # Output: [0, 1, 2, 3, 8] (change only in copy_list)

1. Create a list named values that contains 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10.
2. Slice the list such that you get every second element starting from the end, but not
including the last element.
3. Print the result (it should be 9, 7, 5, 3, 1).

Right Answer:


# Step 1
values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Step 2
sliced_values = values[-2::-2] # Slice to get every second element from the end, excluding the last element
# Step 3
print(sliced_values) # Output: [9, 7, 5, 3, 1]

1. Create a tuple that contains 0, 0, 1, 0, 1, and 1
2. Count the number of 0 using a method.
3. Find the index of the first 1 using a method.
4. Delete the tuple.
Tips: To delete a tuple, you could use del followed by the tuple name.

Right Answer:


# Step 1
binary_tuple = (0, 0, 1, 0, 1, 1)
# Step 2
count_zeros = binary_tuple.count(0)
print(count_zeros) # Output: 3
# Step 3
index_of_first_one = binary_tuple.index(1)
print(index_of_first_one) # Output: 2
# Step 4
del binary_tuple # Deleting the tuple

1. Create a list named fruits containing the following items: "apple", "banana", "cherry".
2. Print the list to ensure it has been created correctly.
3. Create a tuple named vegetables containing the items: "carrot", "broccoli", "lettuce".
4. Print the tuple.

Right Answer:


# Step 1
fruits = ["apple", "banana", "cherry"]
# Step 2
print(fruits) # Output: ['apple', 'banana', 'cherry']
# Step 3
vegetables = ("carrot", "broccoli", "lettuce")
# Step 4
print(vegetables) # Output: ('carrot', 'broccoli', 'lettuce')

1. Given a list named colors that contains "red", "blue", "green", "yellow" and "pink"
2. Print the second and fourth items from the list.
3. Given the tuple named grades that contains "A", "B", "C", "D" and "F"
4. Print the first and last items from the tuple.

Right Answer:


# Step 1
colors = ["red", "blue", "green", "yellow", "pink"]
# Step 2
print(colors[1]) # Output: blue
print(colors[3]) # Output: yellow

# Step 3
grades = ("A", "B", "C", "D", "F")
# Step 4
print(grades[0]) # Output: A
print(grades[-1]) # Output: F

Get In Touch

Kochi, Pala,Ernakulam

+91 9544409513

linuslearning.in@gmail.com

Our Courses
Newsletter

Those people who develop the ability to continuously acquire new and better forms of knowledge that they can apply to their work and to their lives will be the movers and shakers in our society for the indefinite future