Python Program To Check If Number is Odd or Even

Example: num = int(input(“Enter a number: “)) result = [“Even”, “Odd”][num % 2] print(f”The number is {result}.”) Output: Enter a number: 15 The number is Odd. Example: result = “Even” if int(input(“Enter a number: “)) % 2 == 0 else “Odd” print(f”The number is {result}.”) Output: …

Read more

Python Program to Implement Intro Sorting

01. Example: def introsort(data): maxdepth = (len(data).bit_length() – 1)*2 introSortingHelper(data, 0, len(data), maxdepth) def introSortingHelper(data, start, end, maxdepth): if end – start <= 1: return elif maxdepth == 0: heapSorting(data, …

Read more

Python Program to Implement Heap Sorting

01. Example: def heapSorting(data): buildMaxHeap(data) for i in range(len(data) – 1, 0, -1): data[0], data[i] = data[i], data[0] maxHeapify(data, index=0, size=i) def parent(i): return (i – 1)//2 def left(i): return …

Read more