Python 3
Write a binary search function that, instead of returning -1 when the target value is not in the list, raises a TargetNotFound exception (you'll need to define this exception class). Otherwise it should function normally. Name this function bin_except.
The file must be named: bin_except.py

OUTPUT :
![================ RESTART: D: /Coding/Python/targetnotfound.py >>> a = [1,2,5,9,15] >>> bin_except (a, 10) Traceback (most rec](http://img.homeworklib.com/questions/52092770-7e22-11eb-b879-bfd7d1eb8d47.png?x-oss-process=image/resize,w_560)
CODE :
#Define TargetNotFound exception
class TargetNotFound(Exception):
pass
#Function that performs binary search
def bin_except(a,key):
#Initialize l and r
l = 0
r = len(a)-1
#Continue till l<=r
while l<=r:
#Find mid value m
m = (l+r)//2
#Check if key is found
if a[m]==key:
return m
#Change l or r
if a[m]<key:
l = m+1
else:
r = m-1
raise TargetNotFound
Python 3 Write a binary search function that, instead of returning -1 when the target value...
Write a binary search function that, instead of returning -1 when the target value is not in the list, raises a TargetNotFound exception (you'll need to define this exception class). Otherwise it should function normally. Name this function bin_except. The file must be named: bin_except.py PYTHON 3 ONLY
In the PowerPoint slides for lecture 15, you will find a function that performs binary search on a Python list using recursion. Modify that binarySearchRec(alist, item) function so that it performs ternary search on a Python list. Your new function should find two midpoints that divide the list into three approximately equal size segments. If the item being searched for is found at either of the midpoints, the function should return True. If the item being searched for is less...
python: Write a function named "write_values" that takes a key-value store mapping strings to strings as a parameter and writes the values of the input to a file named "persuade.txt" with one element per line. If a file named "persuade.txt" already exists it must be overwritten. The function should not return any value
in python
11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree You will also need to implement a Node class. This class will not be tested, but is needed to implement the BST. Your BST must implement the following methods. You are free to implement additional helper methods. It is recommended you create your own helper methods Constructor: Creates an Empty Tree String Method: Returns the string "Empty Tree" for an empty tree. Otherwise, returns...
(Python) Write a python function that takes a binary search T and a range [a, b] with a ≤ b, where a,b are two integers, and has to decide whether there are two different keys k1,k2 in T whose sum belongs to the given range [a, b] or not. For instance, if the input to the function is some BST T and the range [−1, 4], the function has to decide whether there are two distinct keys k1 , k2...
average_value_in_file / Python 3.x: Your assistance is appreciated, thank you! Write a function named average_value_in_file that accepts a file name as a parameter and reads that file, assumed to be full of numbers, and returns the average (mean) of the numbers in that file. The parameter, filename, gives the name of a file that contains a list of numbers, one per line. You may assume that the file exists and follows the proper format. For example, if a file named...
Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main(). You will write the code for the above functions. Both magic functions (magic-sequential() and magic-binary()) will look for a magic index in a given sorted list of distinct integers. A magic index in a list myList[0 ... n-1] is defined to be an index i such that myList[i] = i . Both functions receive the list as a parameter and return an integer: either the magic index,...
All those points need to be in the code
Project 3 Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort Class River describes river's name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles long and returns false otherwise. Class CTRivers describes collection of CT rivers. It has no data, and it provides the...
Write a program that write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID */ using namespace std; #include <iostream> using namespace std; bool isVowel(char ch); int main() { char ch; … … ...
python 3 needs to read a local JSON file - it doesn't need to access the internet. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as...