Sunday, March 3, 2019

Search elements in list using Count - Python3

list1 = []
len_list = int(input("Enter the number of items to enter into the list: "))
for i in range(len_list):
    new = int(input("Enter the value: "))
    list1.append(new)
i = int(input("Enter a number to search: "))
n=list1.count(i)

print('\nUsing Method')
if i in list1:
    print("Element found in the list")
else:
    print("Element not found in the list")

print('\nUsing list inbuilt function (count)')
if (list1.count(i) > 0):
    print('Element Found')
else:
    print('Not Found')

ScreenShot:

No comments:

Post a Comment