Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Python Data Entry

The document shows examples of how to manipulate lists in Python. It demonstrates concatenating two lists using addition and the extend method. An empty list is created and elements are added using list literals. User input is taken to create a list by splitting on spaces and converting to integers. An element is searched for in the list and a message is printed depending on whether it is found.

Uploaded by

2147033
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Python Data Entry

The document shows examples of how to manipulate lists in Python. It demonstrates concatenating two lists using addition and the extend method. An empty list is created and elements are added using list literals. User input is taken to create a list by splitting on spaces and converting to integers. An element is searched for in the list and a message is printed depending on whether it is found.

Uploaded by

2147033
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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


listl.extend(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

You might also like