92.2k views
5 votes
Q3. Write a script to read in three numbers as arguments, compare them, and list them in an ascending order, execute it in Linux and take screenshot of output.

User Almendar
by
8.3k points

1 Answer

2 votes

Below is a script to read in three numbers as arguments, compare them, and list them in an ascending order:

Python

#!/bin/python3

# Read the three numbers from the command line

num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

num3 = int(input("Enter the third number: "))

# Compare the numbers and store them in a list in ascending order

numbers = [num1, num2, num3]

numbers.sort()

# Print the numbers in ascending order

print("The numbers in ascending order are:")

for number in numbers:

print(number)

So, based on the above, for one to execute the script in Linux, save it as a file named sort_numbers.py and then run the below command in a terminal window as shown below

python sort_numbers.py

User SANITH
by
7.8k points