Our Office
Ernakulam, Kottayam
Email Us
linusfacts@gmail.com
Call Us
+91 9544409513
1. Given a list named days that contains "Monday", "Tuesday", "Wendesday",<br>"Thursday" and "Friday".<br>2. Correct the typo in "Wendesday" to "Wednesday" using the days list.<br>3. Print the list to ensure the change has been made. 1. Create a list named floats that contains 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 and 8.8<br>2. Use slicing to get the elements 2.2, 3.3 and 4.4 in one operation.<br>3. Use slicing to get the elements from 3.3 to the end of the list.<br>4. Use slicing to get the elements from the start of the list to 5.5 included.<br>5. Use slicing to reverse the list. 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 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. Given a tuple named months that contains "Jan", "Feb", "Mach” and "Apr"<br>2. Try to correct the typo in "Mach" to "March".<br>3. What happens?<br>4. Convert the tuple into a list.<br>5. Retry to correct the typo in "Mach" to "March".<br>6. Convert the list into a tuple.<br>7. Print the tuple. 1. Create a list named fishes that contains “catfish”, “perch”, “cod” and “carp”<br>2. Show the last element of the list using two different ways.<br>3. Change the second element of the list by another fish name.<br>4. Print the modified list.

QUESTIONS

1. Given a list named days that contains "Monday", "Tuesday", "Wendesday",
"Thursday" and "Friday".
2. Correct the typo in "Wendesday" to "Wednesday" using the days list.
3. Print the list to ensure the change has been made.

Right Answer:


# Step 1
days = ["Monday", "Tuesday", "Wendesday", "Thursday", "Friday"]
# Step 2
days[2] = "Wednesday" # Correcting the typo
# Step 3
print(days) # Output: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']

1. Create a list named floats that contains 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 and 8.8
2. Use slicing to get the elements 2.2, 3.3 and 4.4 in one operation.
3. Use slicing to get the elements from 3.3 to the end of the list.
4. Use slicing to get the elements from the start of the list to 5.5 included.
5. Use slicing to reverse the list.

Right Answer:


# Step 1
floats = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8]
# Step 2
print(floats[1:4]) # Output: [2.2, 3.3, 4.4]
# Step 3
print(floats[2:]) # Output: [3.3, 4.4, 5.5, 6.6, 7.7, 8.8]
# Step 4
print(floats[:5]) # Output: [1.1, 2.2, 3.3, 4.4, 5.5]
# Step 5
print(floats[::-1]) # Output: [8.8, 7.7, 6.6, 5.5, 4.4, 3.3, 2.2, 1.1]

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 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. Given a tuple named months that contains "Jan", "Feb", "Mach” and "Apr"
2. Try to correct the typo in "Mach" to "March".
3. What happens?
4. Convert the tuple into a list.
5. Retry to correct the typo in "Mach" to "March".
6. Convert the list into a tuple.
7. Print the tuple.

Right Answer:


# Step 1
months = ("Jan", "Feb", "Mach", "Apr")
# Step 2
# Trying to correct the typo will raise an error as tuples are immutable.
# Step 3 - Explanation
# Tuples are immutable, meaning we cannot change their items directly.
# Step 4
months_list = list(months) # Converting tuple to list
# Step 5
months_list[2] = "March" # Correcting the typo
# Step 6
months = tuple(months_list) # Converting the list back to a tuple
# Step 7
print(months) # Output: ('Jan', 'Feb', 'March', 'Apr')

1. Create a list named fishes that contains “catfish”, “perch”, “cod” and “carp”
2. Show the last element of the list using two different ways.
3. Change the second element of the list by another fish name.
4. Print the modified list.

Right Answer:


# Step 1
fishes = ["catfish", "perch", "cod", "carp"]
# Step 2
print(fishes[-1]) # Output: carp (using negative index)
print(fishes[3]) # Output: carp (using positive index)
# Step 3
fishes[1] = "salmon" # Changing the second element to "salmon"
# Step 4
print(fishes) # Output: ['catfish', 'salmon', 'cod', 'carp']

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