0% found this document useful (0 votes)
3 views

Bubble Sort Algorithm

The document contains a Python script that defines functions for sorting a list, finding the maximum value in a list, generating a random list of integers, and testing these functionalities. It prompts the user to input a number, generates a random list of that size, sorts it, and then finds and prints the maximum value. The sorting algorithm used is a basic bubble sort implementation.

Uploaded by

letsgomidas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Bubble Sort Algorithm

The document contains a Python script that defines functions for sorting a list, finding the maximum value in a list, generating a random list of integers, and testing these functionalities. It prompts the user to input a number, generates a random list of that size, sorts it, and then finds and prints the maximum value. The sorting algorithm used is a basic bubble sort implementation.

Uploaded by

letsgomidas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import random

def sort(lst):
# lst = input('Enter a list of numbers: ').split()
# lst = [int(i) for i in lst]
pass_flag = True
while pass_flag == True:
counter = 0
for i in range(len(lst)):
if i == len(lst)-1:
pass
else:
if lst[i] > lst [i+1]:
bigger = lst[i]
smaller = lst[i+1]
lst[i+1] = bigger
lst[i] = smaller
counter += 1

if counter == 0:
pass_flag = False
print(lst)
return lst

def nish_max(lst):
highest = 0
for i in range(0,len(lst)):
if lst[i] > highest:
highest = lst[i]
else:
pass
print(highest)

def rand_lst(number):
store = [random.randint(1,1000000) for i in range(number)]
return store

def test(a):
rand_lst(a)
variable = rand_lst(a)
sort(variable)
nish_max(variable)

num1 = int(input('Enter a number: '))


test(num1)

You might also like