Question

PYTHON The following code implements this algorithm to sort a list of numbers in ascending order....

PYTHON The following code implements this algorithm to sort a list of numbers in ascending order. But some code is missing as indicated by '?'.

def sort_in_place(list_num):
    for i in range(?): 
        for j in range(?): 
            if ?:
                temp = list_num[j]
                list_num[j] = list_num[i]
                list_num[i] = temp

my_list = [23,1,45,20,13,-34]
sort_in_place(my_list)
print(my_list)

Modify the three lines of code in the program below so that the output is

[-34, 1, 13, 20, 23, 45]

Homework Answers

Answer #1
def sort_in_place(list_num):
    for i in range(len(list_num)):
        for j in range(len(list_num)):
            if list_num[i]<list_num[j]:
                temp = list_num[j]
                list_num[j] = list_num[i]
                list_num[i] = temp

my_list = [23,1,45,20,13,-34]
sort_in_place(my_list)
print(my_list)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following code implements this algorithm to sort a list of numbers in ascending order. But...
The following code implements this algorithm to sort a list of numbers in ascending order. But some code is missing as indicated by '?'. def sort_in_place(list_num):     for i in range(?):         for j in range(?):             if ?:                 temp = list_num[j]                 list_num[j] = list_num[i]                 list_num[i] = temp my_list = [23,1,45,20,13,-34] sort_in_place(my_list) print(my_list)
Question2: The following function is supposed to receive a list of numbers and a number as...
Question2: The following function is supposed to receive a list of numbers and a number as the input parameters. The function finds all occurrences of number inside the list and removes them from the list and eventually returns the results. Do you think this function will work as expected? If yes, please mention and if no, please fix it. def function(listOfNumbers, number): for i in range(len(listOfNumbers)): if listOfNumbers[i]==number: listOfNumbers.remove(number) return listOfNumbers newList = function([3,4,1,3,4,7,8,1,2,3,4,6,8], 3) print("After removing the occurrences of...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following questions using the list below. You can record your answers in the essay textbox. data = [5,3,7] A. Write code to replace the value in the 0 position with the number 8. B. Add the value 10 to the end of the list. C. Insert the value 22 after position 1 in the list. D. Remove the value at position 2. E. Sort the...
Write an R code to print out all even numbers from the following numbers list in...
Write an R code to print out all even numbers from the following numbers list in the same order they are received. Write the code so it does not print any numbers that come after 83. numbers = [951, 40, 84, 51, 60, 69, 48, 19, 61, 85, 98, 50, 72, 47, 44, 61, 83, 65, 41, 51, 63, 61, 65, 75, 21, 30, 84, 92, 23]
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
Language: Python Write a program to simulate an experiment of tossing a fair coin 16 times...
Language: Python Write a program to simulate an experiment of tossing a fair coin 16 times and counting the number of heads. Repeat this experiment 10**5 times to obtain the number of heads for every 16 tosses; save the number of heads in a vector of size 10**5 (call it headCounts). You should be able to do this in 1-3 lines of numpy code. (Use np.random.uniform1 to generate a 2d array of 10**5 x 16 random numbers between 0 and...