assignment 1
In [1]: # Define two Lists
listl = [1, 2, 3]
list2 = [4, 5, 6]
# Concatenate the Lists
concatenated list = listl + list2
# Display the concatenated List
print(concatenated_list)
[1, 2, 3, 4, 5, 6]
In [2]: # Define two Lists
listl = [1, 2, 3]
list2 = [4, 5, 6]
# Concatenate the Lists using extend()
[Link](list2)
# Display the concatenated List
print(listl)
[1, 2, 3, 4, 5, 6]
In [3]: # Create an empty List using the List constructor
my_list = list()
# Add elements to the List using List Literals
my_list += [1, 2, 3]
# Display the List
print(my_list)
[1, 2, 3]
In [4]: # Get a string from the user
user_input = input("Enter a list of numbers separated by spaces: ")
# Split the string into a List of substrings
my_list = user_input.split()
# Convert the substrings to integers
my_list = [int(i) for i in my_list]
# Display the List
print("The list is:", my_list)
# Get the element to search for from the user
search_element = int(input("Enter an element to search for: "))
# Check if the element is in the List
if search_element in my_list:
# If the element is in the List, display a message
print(search_element, "is in the list.")
else:
# If the element is not in the List, display a different message
print(search_element, "is not in the list.")
Enter a list of numbers separated by spaces: 94 93 99 97 96 96 98
The list is: [94, 93, 99, 97, 96, 96, 98]
Enter an element to search for: 96
96 is in the list.
1/3