Computer Science
Write a program that inputs a list, replicates it twice and then prints the sorted list in ascending and descending orders.
Answer
List1 = eval(input("Enter the list: "))
List2 = List1 * 2
List2.sort()
print("Sorted list in ascending order:", List2)
List2.sort(reverse=True)
print("Sorted list in descending order:", List2)Output
Enter the list: [4, 5, 2, 9, 1, 6]
Sorted list in ascending order: [1, 1, 2, 2, 4, 4, 5, 5, 6, 6, 9, 9]
Sorted list in descending order: [9, 9, 6, 6, 5, 5, 4, 4, 2, 2, 1, 1]
Related Questions
Draw the structure of the components of a computer and briefly explain the following.
(a) Input Unit
(b) Output Unit
(c) Central Processing Unit
(d) Primary Memory
(e) Secondary Memory
Write a menu-driven program to implement a simple calculator for two numbers given by the user.
Write a program to create a dictionary with the roll number, name and marks of n students in a class, and display the names of students who have secured marks above 75.
Explain any five social media etiquettes.