Design a program that allows the user to enter 5 names into a String array. Sort the array in ascending (alphabetical) order and display its contents. Search the array for a specific name that the user wants. (python)
names = [] for i in range(5): name = input("Enter name: ") names.append(name) names.sort() target = input("Enter name to search: ") lower = 0 upper = len(names)-1 result = None while upper >= lower: mid = lower + ((upper - lower) // 2) if names[mid] == target: result = mid break elif names[mid] > target: upper = mid - 1 else: lower = mid + 1 if(result==None): print(target,"not found in the list") else: print(target, "found in the list")
Get Answers For Free
Most questions answered within 1 hours.