Aim:
To write a Python program that accepts n numbers from the user, stores them in a list, and removes duplicate elements.
Algorithm:
- Start the program.
- Accept the number of elements (n) from the user.
- Create an empty list.
- Use a loop to input n numbers and append them to the list.
- Convert the list to a set to remove duplicate elements.
- Convert the set back to a list.
- Display the list without duplicates.
- Stop the program.
Program:
n = int(input("Enter the number of elements: "))numbers = []for i in range(n):
num = int(input("Enter number: "))
numbers.append(num)print("Original List:", numbers)# Remove duplicates
unique_numbers = list(set(numbers))print("List after removing duplicates:", unique_numbers)
Sample Output:
Enter the number of elements: 6
Enter number: 2
Enter number: 5
Enter number: 2
Enter number: 7
Enter number: 5
Enter number: 9Original List: [2, 5, 2, 7, 5, 9]
List after removing duplicates: [2, 5, 7, 9]
Oral Questions:
- What is a list in Python?
- How do you create a list in Python?
- What is the use of the append() function in a list?
- What is a duplicate element in a list?
- How does the set() function remove duplicates?
