Data Organization - Python Programming Exercise

In this exercise, you will develop a Python program that prompts the user for 10 integer numbers (ranging from -1000 to 1000), sorts them, and displays them in sorted order. This exercise is perfect for practicing input handling, sorting algorithms, and loops in Python. By prompting the user for 10 integer numbers, sorting them, and displaying them in sorted order, you will gain hands-on experience in handling user input and output in Python. This exercise not only reinforces your understanding of sorting algorithms but also helps you develop efficient coding practices for managing user interactions.

 Category

Arrays, Lists, and Strings

 Exercise

Data Organization

 Objective

Develop a Python program to prompt the user for 10 integer numbers (ranging from -1000 to 1000), sort them, and display them in sorted order.

 Example Python Exercise

 Copy Python Code
# Create an empty list to store the integers
numbers = []

# Prompt the user for 10 integers
for i in range(10):
    while True:
        try:
            num = int(input(f"Enter integer number {i+1} (between -1000 and 1000): "))
            if -1000 <= num <= 1000:
                numbers.append(num)
                break
            else:
                print("Please enter a number between -1000 and 1000.")
        except ValueError:
            print("Invalid input. Please enter an integer.")

# Sort the numbers in ascending order
numbers.sort()

# Display the sorted numbers
print("The sorted numbers are:")
for num in numbers:
    print(num)

 Output

Enter integer number 1 (between -1000 and 1000): 300
Enter integer number 2 (between -1000 and 1000): 100
Enter integer number 3 (between -1000 and 1000): -200
Enter integer number 4 (between -1000 and 1000): 500
Enter integer number 5 (between -1000 and 1000): 600
Enter integer number 6 (between -1000 and 1000): 0
Enter integer number 7 (between -1000 and 1000): -50
Enter integer number 8 (between -1000 and 1000): -100
Enter integer number 9 (between -1000 and 1000): 400
Enter integer number 10 (between -1000 and 1000): 200

The sorted numbers are:
-200
-100
-50
0
100
200
300
400
500
600

 Share this Python Exercise

 More Python Programming Exercises of Arrays, Lists, and Strings

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Screen Buffer Using 2D Array

    In this exercise, you will develop a Python program that declares a 70x20 two-dimensional array of characters, "draws" 80 letters (X, for example) in random positions...

  •  2D Array: Display Circle

    In this exercise, you will develop a Python program that creates a 70x20 two-dimensional array of characters, "draws" a circle with a radius of 8 inside it, and displ...

  •  Software Applications

    In this exercise, you will develop a Python program that can store up to 1,000 records of software applications. For each application, you must keep the following dat...

  •  Exercise tasks

    In this exercise, you will develop a Python program that can store up to 2,000 "to-do tasks". For each task, it must keep the following data: Date (a set of 3 ...

  •  Home Finances

    In this exercise, you will develop a Python program that can store up to 10,000 records of expenses and incomes to create a small household accounting system. For eac...

  •  Array Reversal

    This Python program prompts the user to input 5 numbers and stores them in an array (or list in Python). After all the numbers are entered, the program displays them ...