# How to Sort in Ascending Order using Quicksort in Python

In this tutorial, we will program 'How to Sort in Ascending Order using Quicksort in Python.' We will learn how to sort a list in ascending order. The objective is to teach you how to sort a list using the Quicksort algorithm. I will provide a sample program to demonstrate the actual coding process in this tutorial.

This topic is very easy to understand. Just follow the instructions I provide, and you can do it yourself with ease. The program I will show you covers the basics of programming to sort a list in ascending order. I will do my best to provide you with a simple method for sorting a list. So, let's start with the coding.

## Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
`def quicksort(arr):	if len(arr) <= 1:		return arr	else:		pivot = arr[0]		left = [x for x in arr[1:] if x < pivot]		right = [x for x in arr[1:] if x >= pivot]		return quicksort(left) + [pivot] + quicksort(right) ret = False while True:        print("\n================== Sort in Ascending Order using Quicksort ==================\n\n")          arr = [-1, -3, 2, 8, 5, 0, 10, 9, -2]        sorted_arr = quicksort(arr)         print("Original Order: ",arr)        print("\n")        print("Ascending Order:", sorted_arr)         opt = input("\nDo you want to try again?(yes/no): ")         if opt.lower() == 'yes':                ret=False        elif opt.lower() == 'no':                ret=True                print("Exiting program....")         else:                print("Please enter yes/no:")                break         if ret == False:                continue`

This script sorts the array [-1, -3, 2, 8, 5, 0, 10, 9, -2] in ascending order using the quicksort algorithm. It repeatedly prompts the user to rerun the sorting process or exit the program. Each time, it prints the original array and its sorted version, allowing the user to choose whether to continue or exit based on their input.

## Output:

There you have it we successfully created How to Sort in Ascending Order using Quicksort in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials