I have given you the linear search code example on the video and I want you to go through the code and adjust the code. In the following code, list consists of number 4 twice however when you execute this code you find only the first 4. Please adjust your code to find both 4’s on the list def linear_search(list1,key): for i in range(len(list1)): if key==list1[i]: print("Element is found at index", i) break else: print("The element is not found") list1=[4,5,10,4,9,21] key=int(input("Enter a key number: ")) linear_search(list1,key)
I have given you the linear search code example on the video and I want you to go through the code and adjust the code. In the following code, list consists of number 4 twice however when you execute this code you find only the first 4. Please adjust your code to find both 4’s on the list def linear_search(list1,key): for i in range(len(list1)): if key==list1[i]: print("Element is found at index", i) break else: print("The element is not found") list1=[4,5,10,4,9,21] key=int(input("Enter a key number: ")) linear_search(list1,key)
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
I have given you the linear search code example on the video and I want you to go through the code and adjust the code. In the following code, list consists of number 4 twice however when you execute this code you find only the first 4. Please adjust your code to find both 4’s on the list
def linear_search(list1,key): for i in range(len(list1)):
if key==list1[i]:
print("Element is found at index", i)
break else:
print("The element is not found") list1=[4,5,10,4,9,21]
key=int(input("Enter a key number: ")) linear_search(list1,key)
![Sure! Here is the transcription of the text from the image:
---
**Module 12 Lab**
I have given you the linear search code example on the video and I want you to go through the code and adjust the code. In the following code, list consists of number 4 twice however when you execute this code you find only the first 4. Please adjust your code to find both 4's on the list.
```python
def linear_search(list1, key):
for i in range(len(list1)):
if key == list1[i]:
print("Element is found at index", i)
break
else:
print("The element is not found")
list1 = [4, 5, 10, 4, 9, 21]
key = int(input("Enter a key number: "))
linear_search(list1, key)
```
---
This text is suitable for an educational website where students or users are learning about algorithms, specifically the linear search algorithm in Python.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F70530e70-0e1d-481d-b68e-88cdcb274817%2Fb35f413b-49e6-4a91-bfaa-797950be6d74%2F656obr_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Sure! Here is the transcription of the text from the image:
---
**Module 12 Lab**
I have given you the linear search code example on the video and I want you to go through the code and adjust the code. In the following code, list consists of number 4 twice however when you execute this code you find only the first 4. Please adjust your code to find both 4's on the list.
```python
def linear_search(list1, key):
for i in range(len(list1)):
if key == list1[i]:
print("Element is found at index", i)
break
else:
print("The element is not found")
list1 = [4, 5, 10, 4, 9, 21]
key = int(input("Enter a key number: "))
linear_search(list1, key)
```
---
This text is suitable for an educational website where students or users are learning about algorithms, specifically the linear search algorithm in Python.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education