Answer:
There are multiple ways to solve the given problem, I will be presenting the most simple and easy way of solving this problem in few lines of code.
Python code:
def is_sorted(user_list):
return user_list == sorted(user_list)
user_list=input("Please enter a list: ")
user_list = user_list.split()
print(is_sorted(user_list))
print("Your list: ", user_list)
Explanation:
A function is_sorted is created which takes a list as input and using the sorted() function of python which returns true when the list is sorted in ascending order and returns false when the list is not sorted in ascending order.
Driver code includes getting input list from the user and using split() function to create a list separated by space then printing the output of is_sorted function and in the last printing the contents of that list.
Output:
Please enter a list: 1 3 6 9
True
Your list: ['1', '3', '6', '9']
Please enter a list: 15 7 2 20
False
Your list: ['15', '7', '2', '20']