Programming Examples
Write a program that takes as input a list having a mix of 10 positive numbers and a key value.
Write a program that takes as input a list having a mix of 10 positive numbers and a key value.
Apply linear search to find whether the key is present in the list or not.
If input is: [10, 50, 30, 70, 80, 20, 90, 40], key = 30
Then output should be: Yes
If input is: [10, 50, 30, 70, 80, 20, 90, 40], key = 15
Then output should be: No
numbers = eval(input("Enter numbers separated by space: "))
key = int(input("Enter key to search: "))
found = False
for num in numbers:
if num == key:
found = True
break
if found:
print("Yes")
else:
print("No")
Output/ Explanation: