From 8e192f3f70317be7f18829bada01682b09def6ae Mon Sep 17 00:00:00 2001 From: Prathima Kadari Date: Wed, 19 May 2021 21:08:15 +0530 Subject: [PATCH 1/2] Added linear search program --- LinearSearch.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 LinearSearch.py diff --git a/LinearSearch.py b/LinearSearch.py new file mode 100644 index 0000000..85bc369 --- /dev/null +++ b/LinearSearch.py @@ -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) From 12467baca8f10a4359288ddc321912e8c23e6e4d Mon Sep 17 00:00:00 2001 From: Prathima Kadari Date: Wed, 19 May 2021 21:12:02 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e052e20..c90bfcd 100644 --- a/README.md +++ b/README.md @@ -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) |