Our Office
Ernakulam, Kottayam
Email Us
linusfacts@gmail.com
Call Us
+91 9544409513
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. 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 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. Ask the user to provide three numerical inputs.<br>2. Create a tuple out of them.<br>3. If the sum of the first and second elements of the tuple is greater than the third, print<br>the tuple in reverse.<br>4. Otherwise, print the tuple normally. 1. Create a list named integers that contains 0, 1 and 3.<br>2. Add the number 4 to the end of the list using two different methods.<br>3. Add the number 2 in the list at the correct index to get a sequence.<br>4. Print the list, it should display 0, 1, 2, 3, 4.<br>5. Create a new list that contains 5, 6, 7 and 8.<br>6. Add this new list at the end of the integers list.<br>7. Remove the number 0 from the list. 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 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. 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.

QUESTIONS

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

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 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. Ask the user to provide three numerical inputs.
2. Create a tuple out of them.
3. If the sum of the first and second elements of the tuple is greater than the third, print
the tuple in reverse.
4. Otherwise, print the tuple normally.

Right Answer:


# Step 1
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
# Step 2
num_tuple = (num1, num2, num3)
# Step 3 and Step 4
if num1 + num2 > num3:
print(num_tuple[::-1]) # Print the tuple in reverse
else:
print(num_tuple) # Print the tuple normally

1. Create a list named integers that contains 0, 1 and 3.
2. Add the number 4 to the end of the list using two different methods.
3. Add the number 2 in the list at the correct index to get a sequence.
4. Print the list, it should display 0, 1, 2, 3, 4.
5. Create a new list that contains 5, 6, 7 and 8.
6. Add this new list at the end of the integers list.
7. Remove the number 0 from the list.

Right Answer:


# Step 1
integers = [0, 1, 3]
# Step 2
integers.append(4) # Method 1: Using append()
integers += [4] # Method 2: Using += operator
# Step 3
integers.insert(2, 2) # Insert 2 at the correct index to create a sequence
# Step 4
print(integers) # Output: [0, 1, 2, 3, 4]
# Step 5
new_list = [5, 6, 7, 8]
# Step 6
integers.extend(new_list) # Adding the new list at the end of the integers list
# Step 7
integers.remove(0) # Removing the number 0 from the list
print(integers) # Output: [1, 2, 3, 4, 5, 6, 7, 8]

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

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.")

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