Program To Check If An Element Exists In The List Or Not If That Element Does Not Exist Then Add
November 13, 2022 by Primegyan 5.03k
O Level Practical July 2022 Old Paper Solution - python m3-r5
Write a program to check if an element exists in the list or not. if that element does not exist then add that particular element in the list.
numbers=[4,2,7,1,8,3,6]
print("Original lists item: ",numbers)
chk=int(input("Enter that item which you want to check"))
if chk in numbers:
print("Number is present in list")
else:
print("Number Does not exist")
numbers.append(chk)
print("Item added Succussfully: ", numbers)
OUTPUT: First time Running Program
Original lists item: [4, 2, 7, 1, 8, 3, 6]
Enter that item which you want to check8
Number is present in list
Second time Running Program
Original lists item: [4, 2, 7, 1, 8, 3, 6]
Enter that item which you want to check24
Number Does not exist
Item added Succussfully: [4, 2, 7, 1, 8, 3, 6, 24]
Write a program to check if an element exists in the list or not. if that element does not exist then add that particular element in the list. - Video Solution