Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions LinearSearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Function for linear search operation
def linear_search(array, element):
for i in range(len(array)):

# Check if element is in specific index of the array
if array[i] == element:
print (f"{element} is in {i+1} position")

# If the element is not present in the array, it prints not found
if element not in array:
print ("Not found")

# Get the size of the array from the user
length = int(input('Enter the number of elements: '))
my_list = []

# Get the input for the list
for i in range(length):
element = int(input(f"Enter {i+1} element: "))
my_list.append(element)

# Get the element whose position is to be searched for
position = int(input('Enter the element whose position you want to find: '))

linear_search(my_list,position)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Thanks!
|[FileComparison.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/FileComparison.py)| Downloads and unzip zip files from a webpage, compares them and prints out duplicate sentences|[Aakanksha](https://github.com/accakks) |
| [TicTacToe.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/TicTacToe.py) | 2 Player Tic Tac Toe | [Aakanksha](https://github.com/accakks) |
| [RockPaperScissors.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/RockPaperScissors.py) | Rock Paper Scissors with Computer | [Aakanksha](https://github.com/accakks) |
| [LinearSearch.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/LinearSearch.py) | Linear Search | [Prathima Kadari](https://github.com/prathimacode-hub) |
| [countCharacter.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/countCharacter.py) | Counts number of times each character occurs in the input string. | [Aakanksha](https://github.com/accakks) |
| temperature_table.py | Prints a table of fahrenheit and Celsius values | [Eventhisone](https://github.com/eventhisone)
| [calculatePi.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/calculatePi.py) | Calculates PI to a specified number of digits of accuracy. | [Joseph-Acevedo](https://github.com/joseph-acevedo) |
Expand Down