Question

Write a program that takes a list of integer numbers from a user and creates a...

Write a program that takes a list of integer numbers from a user and creates a new sorted in ascending order list. As output you need to print original list and sorted one.

use list and while

python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def sort(A):
    for i in range(len(A)):
        ind = i
        for j in range(i + 1, len(A)):
            if A[ind] > A[j]:
                ind = j
        A[i], A[ind] = A[ind], A[i]
    return A

if __name__ == '__main__':
    s = input("Enter list of numbers separated by space: ")
    lst = [int(x) for x in s.split(" ")]
    print(lst)
    res = sort(lst)
    print(res)

Output:

Enter list of numbers separated by space: 4 2 3 1 5 [4, 2, 3, 1, 5] [1, 2, 3, 4, 5] Process finished with exit code 0

Note: Please comment below if you have any doubts

Add a comment
Know the answer?
Add Answer to:
Write a program that takes a list of integer numbers from a user and creates a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • Write a program which will take a list of integer number from the user as input...

    Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...

  • In PYTHON Write a program that # 1) Creates a list of 25 numbers that are...

    In PYTHON Write a program that # 1) Creates a list of 25 numbers that are all different # 2) Takes a user-input number and then determines which number in the list is closest to the user-input number.

  • Write a Python function that creates and returns a list of prime numbers between 2 and...

    Write a Python function that creates and returns a list of prime numbers between 2 and N, inclusive, sorted in increasing order. A prime number is a number that is divisible only by 1 and itself. This function takes in an integer and returns a list of integers.

  • USING PYTHON 1. Write a small program that asks for an integer number from the user...

    USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)

  • Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers...

    Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build a list of the specified length made up by repeating the numbers from the input list as many times as required. That is, the output list has the specified length same as the length specified by the input integer. For example: fillNum 4 [5,6,7,8,9,10] should output [5,6,7,8] fillNum 9 [4,3,2,1] should output [4,3,2,1]

  • Exercise 9.2 Write a Python program that collects from the user a single integer. Have the...

    Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...

  • Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build...

    Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build a list of the specified length made up by repeating the numbers from the input list as many times as required. That is, the output list has the specified length same as the length specified by the input integer. For example: fillNum 4 [5,6,7,8,9,10] should output [5,6,7,8] fillNum 9 [4,3,2,1] should output [4,3,2,1,4,3,2,1,4] fillNum 7 [1,2,3] should output [1,2,3,1,2,3,1]

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT