From 04e40e86234eb9f7cb971d7280db38d9c1244dce Mon Sep 17 00:00:00 2001 From: Kshitij Date: Thu, 16 Jan 2025 11:00:08 +0530 Subject: [PATCH] Added code for selection sort. --- Codes/Assignment-A3.I.py | 41 ++++++++++++++++++++++++++++++++++++++++ README.md | 3 +++ 2 files changed, 44 insertions(+) create mode 100644 Codes/Assignment-A3.I.py diff --git a/Codes/Assignment-A3.I.py b/Codes/Assignment-A3.I.py new file mode 100644 index 0000000..58a5564 --- /dev/null +++ b/Codes/Assignment-A3.I.py @@ -0,0 +1,41 @@ +# Assignment-A3.I (Selection Sort) + +numbers=[] + +# Function to take input for numbers +def input_numbers(): + total=int(input("How many numbers you wish to enter?\nTotal numbers:\t")) + for i in range(1, total+1): + numIn=float(input(f"Enter number {i}:\t")) + numbers.append(numIn) + print("The numbers you've entered are:\t", numbers) + +# Function for selection sort +def selection(): + for i in range(len(numbers)): + min_index=i + for j in range(i+1, len(numbers)): + if numbers[j] < numbers[min_index]: + min_index=j + numbers[i], numbers[min_index] = numbers[min_index], numbers[i] + print("Numbers sorted in ascending order using selection sort:\t", numbers) + +def choose_optn(): + while True: + print("Choose an option from the menu below:") + print("1 -> Input numbers") + print("2 -> Apply Selection Sorting") + print("3 -> Exit") + optn=int(input("Choose an option (1-3):\t")) + + if optn==1: + input_numbers() + elif optn==2: + selection() + elif optn==3: + print("\n## END OF CODE\n") + quit() + else: + print("\nPlease choose a valid option (1-3).\n") +choose_optn() + diff --git a/README.md b/README.md index ce24bb4..4558f0f 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ ### Notes ### Codes +1. [Assignment-A1 (DFS | BFS)]() +2. [Assignment-A2 (A star algorithm)]() +3. [Assignment-A3.I (Selection Sort)](Codes/Assignment-A3.I.py) ### Practical