Answer to Question #318692 in Python for jhon

Question #318692

Create a list of numbers consisting of your student number

and find any s

pecific number inside the list

,

you can use listsearch or binary

search

this list. Then do a sorting to sort the numbers in this list from

least to greatest.

Keep the

repetitive

numbers as it is.



1
Expert's answer
2022-03-26T12:40:39-0400
def find(L, n):
    """Find n in list L
    """
    for x in L:
        if x == n:
            return True
    return False


def sort(L):
    """Sort list L in accecing order
       use insertion sort
    """
    n = len(L)
    for i in range(1,n):
        j = i
        while j > 0 and L[j-1] > L[j]:
            L[j-1], L[j] = L[j], L[j-1]
            j -= 1


def main():
    L = [1, 5, 8, 4, 3, 2, 1, 0]


    n = 8
    if find(L, n):
        print(n, ' is in the list')
    else:
        print(n, ' is not in the list')
    
    sort(L)
    print('Soreted list:', L)


main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS