๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

is_sorted that takes a list

โ† All Python Programs

Aim:

☛   Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted in ascending order and False otherwise.

Solution :


PROGRAM: (is_sorted.py)

 
def is_sorted(user_list):
	new_list = sorted(user_list)
	print(" Your Sorted list : " , sorted(user_list))
	if(new_list == user_list):
		return True
	else:
		return False
user_list = [int(x) for x in input("Please enter a list: ").split()]
print(" Your list : " , user_list)
print(is_sorted(user_list))

OUTPUT:

 
Please enter a list: 7 8 9 4 5 6 10 12
 Your list :  [7, 8, 9, 4, 5, 6, 10, 12]
 Your Sorted list :  [4, 5, 6, 7, 8, 9, 10, 12]
False



๐Ÿ’ป Run This Python Program

is_sorted that takes a list
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals