Informatics Practices
Write a program in Python to input elements in an empty list. Also delete an element from the list which a user will input.
Python List Manipulation
2 Likes
Answer
m = []
n = int(input("Enter the number of elements in list: "))
for i in range(n):
element = input("Enter an element to add to the list: ")
m.append(element)
print("List before deletion:", m)
e = input("Enter the element to delete from the list: ")
m.remove(e)
print("List after deletion:", m)
Output
Enter the number of elements in list: 5
Enter an element to add to the list: 3
Enter an element to add to the list: 6
Enter an element to add to the list: 9
Enter an element to add to the list: 12
Enter an element to add to the list: 15
List before deletion: ['3', '6', '9', '12', '15']
Enter the element to delete from the list: 12
List after deletion: ['3', '6', '9', '15']
Answered By
3 Likes
Related Questions
Rohit, a Librarian has created a Table Book with the following fields:
Bookid, Bookname, Author and Price. He has entered 20 records in the table.
Which command should he use to do the following:
(i) To change the price of Computer Science book from 450 to 500.
(ii) To insert Primary Key in the table.
(iii) What is the difference between delete and drop command.
The data type list is an ordered sequence which is mutable and made up of one or more elements. Unlike a string which consists of only characters, a list can have elements of different data types such as integer, float, string, tuple or even another list. A list is very useful to group elements of mixed data types. Elements of a list are enclosed in square brackets and are separated by comma.
(i) How is a list different from a dictionary?
(ii) Find the values of y and z after execution:
x=[2, 3] y=[30, 40] z=[88, 99] y.extend(x) z.append(x) print (y) print (z)
Consider the following list.
emp=["Aditya", 40000, "Deepak",50000, "Yashmit", 60000, "Bhavya", 80000]
(i) To Insert the value "Ramit" at index number 4.
(ii) To check whether element 50000 is present in the list or not.
(iii) To display the first 3 elements from the list.
(iv) To remove the fifth element from the list.
An organization wants to create a table EMPLOYEE, DEPENDENT to maintain the following details about its employees and their dependents.
EMPLOYEE (EmployeeID, AadhaarNumber, Name, Address, Department)
DEPENDENT (EmployeeId, DependentName, Relationship).
There are 10 records each in both tables.
(i) Name the attributes of the Employee, which can be used as candidate keys.
(ii) What is the degree of the Employee Table?
(iii) What is the Cardinality of a Dependent Table?
(iv) Which is the Primary key of Dependent Table?