Our Office
Ernakulam, Kottayam
Email Us
linusfacts@gmail.com
Call Us
+91 9544409513
1. Create a list named mylist that contains ‘abc’, False, 1 and 3.14159.<br>2. Change False and 1 to True and 0 in one operation.<br>3. Extract the element ‘abc’ from the list and assign it to a variable in one operation.<br>4. Print that variable.<br>5. Assign the 3 list elements into 3 variables in one operation.<br>6. Print these variables. 1. Given a list named animals that contains "cat", "dog" and “apple”<br>2. Remove the “apple” from the list.<br>3. Print the list.<br>4. Add "rabbit" to the list.<br>5. Print the list. You can’t use any loop for this exercise.<br>1. Create a list named numbers that contains 3, 4, 5, 1 and 2.<br>2. Ask the user to input a number.<br>3. Compare the user's number to the maximum of the list.<br>4. Print whether it is higher or lower than the maximum of the list.<br>5. Do the same using another method. 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 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. 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. 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 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 list named sports that contains "Football", "Basketball", "Swimming" and<br>"Tennis".<br>2. Ask the user for their favorite sport.<br>3. Print "We love that too!" if the user's favorite sport is in the list. 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.

QUESTIONS

1. Create a list named mylist that contains ‘abc’, False, 1 and 3.14159.
2. Change False and 1 to True and 0 in one operation.
3. Extract the element ‘abc’ from the list and assign it to a variable in one operation.
4. Print that variable.
5. Assign the 3 list elements into 3 variables in one operation.
6. Print these variables.

Right Answer:


# Step 1
mylist = ['abc', False, 1, 3.14159]
# Step 2
mylist[1:3] = [True, 0] # Change False and 1 to True and 0
# Step 3
abc_var = mylist.pop(0) # Extract 'abc' and assign it to abc_var
print(abc_var) # Output: 'abc'
# Step 4
var1, var2, var3 = mylist # Assign the remaining list elements to variables
# Step 5
print(var1, var2, var3) # Output: True, 0, 3.14159

1. Given a list named animals that contains "cat", "dog" and “apple”
2. Remove the “apple” from the list.
3. Print the list.
4. Add "rabbit" to the list.
5. Print the list.

Right Answer:


# Step 1
animals = ["cat", "dog", "apple"]
# Step 2
animals.remove("apple") # Removing "apple" from the list
# Step 3
print(animals) # Output: ['cat', 'dog']

# Step 4
animals.append("rabbit") # Adding "rabbit" to the list
# Step 5
print(animals) # Output: ['cat', 'dog', 'rabbit']

You can’t use any loop for this exercise.
1. Create a list named numbers that contains 3, 4, 5, 1 and 2.
2. Ask the user to input a number.
3. Compare the user's number to the maximum of the list.
4. Print whether it is higher or lower than the maximum of the list.
5. Do the same using another method.

Right Answer:


# Step 1
numbers = [3, 4, 5, 1, 2]
# Step 2
user_number = int(input("Enter a number: "))
# Step 3
if user_number > max(numbers):
print("Your number is higher than the maximum of the list.")
else:
print("Your number is lower than or equal to the maximum of the list.")
# Step 5 - Alternative method
maximum = sorted(numbers)[-1] # Sorting to find the max value
if user_number > maximum:
print("Your number is higher than the maximum of the list.")
else:
print("Your number is lower than or equal to the maximum of the list.")

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 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']

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. 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 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 list named sports that contains "Football", "Basketball", "Swimming" and
"Tennis".
2. Ask the user for their favorite sport.
3. Print "We love that too!" if the user's favorite sport is in the list.

Right Answer:


# Step 1
sports = ["Football", "Basketball", "Swimming", "Tennis"]
# Step 2
favorite_sport = input("Enter your favorite sport: ")
# Step 3
if favorite_sport in sports:
print("We love that too!")
else:
print("That's a great sport, but not on our list.")

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

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