Write a recursive function called binary search

Assignment Help Python Programming
Reference no: EM131849650

1. Write a class of objects called matrix_2 that act like a 2x2 matrix. Make sure to include:
a. __init__ method
b. __add__ method (add two 2x2 matrices)
c. __mul__ method (multiply two 2x2 matrices)
d. __str__ method
e. determinant() a method that finds a matrix's determinant
f. invert() a method that finds a matrix's inverse if it has one or returns 'singular matrix' if it does not

2. Write a recursive function called binary_search() that accepts as arguments a number (your function should work for float and integer types) and a list of numbers sorted in ascending order. Your function may need to accept more arguments, but all other arguments should be given a default value so that they do not have to be entered. Then use the binary search algorithm, implemented recursively, to return either an index that contains the number (there may be more than one, but you need only return one) or 'number not in list'.

3. A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:

1/2=0.5,
1/3=0.(3),
1/4=0.25,
1/5=0.2,
1/6=0.1(6),
1/7=0.(142857),
1/8=0.125,
1/9=0.(1),
1/10=0.1
Where 0.1(

1. Write a class of objects called matrix_2 that act like a 2x2 matrix. Make sure to include:
a. __init__ method
b. __add__ method (add two 2x2 matrices)
c. __mul__ method (multiply two 2x2 matrices)
d. __str__ method
e. determinant() a method that finds a matrix's determinant
f. invert() a method that finds a matrix's inverse if it has one or returns 'singular matrix' if it does not

2. Write a recursive function called binary_search() that accepts as arguments a number (your function should work for float and integer types) and a list of numbers sorted in ascending order. Your function may need to accept more arguments, but all other arguments should be given a default value so that they do not have to be entered. Then use the binary search algorithm, implemented recursively, to return either an index that contains the number (there may be more than one, but you need only return one) or 'number not in list'.

3. A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:

1/2=0.5,
1/3=0.(3),
1/4=0.25,
1/5=0.2,
1/6=0.1(6),
1/7=0.(142857),
1/8=0.125,
1/9=0.(1),
1/10=0.1

Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.

Write a function decimal() that accepts as input an integer denominator and returns a string with the decimal representation of that fraction (with no trailing zeros, a leading 0. and any numbers that repeat infinitely in parenthesis as above). Hint: How would you implement long division in python? When do you know that your division process is looping?

4. An alternade is a word in which its letters, taken alternatively in a strict sequence, and used in the same order as the original word, make up at least two other words. All letters must be used, but the smaller words are not necessarily of the same length. For example, a word with seven letters where every second letter is used will produce a four-letter word and a three-letter word. Here are two examples:
"board": makes "bad" and "or".
"waists": makes "wit" and "ass".
Using the word list attached, write a function, alternade, that accepts as an argument the file name for the dictionary and then goes through each word in the list and tries to make two smaller words using every second letter. The smaller words must also be members of the list. Print the words to the screen in the above fashion.

5. Write a function called checksum() that accepts as input a filename. The function takes the text of the file and sums the letters (upper and lowercase letters have the same value) for 'a' = 1, 'b' = 2, 'c' = 3, ... For example 'word' would give 'w'+ 'o' + 'r' +'d' = 23 + 15 + 18 + 4 = 60. The function should return the integer sum of all the letters in the file.

6. Write a function called word_lengths() that accepts a list of words and using a dictionary comprehension returns a dictionary whose keys are integers and values are the set of words from the input list whose length are that of its key. The values should be lower cased. The function should be as follows:
defword_lengths(input_list):
"""
documentation here
"""
return {dictionary comprehension here}

7. In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

It is possible to make £2 in the following way:

1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p

Write a function, make_change() that accepts an integer number of pence and calculates how many different ways one can make change for that amount using any number of coins? What is the answer for 200 pence?

8. A certain childrens game involves starting with a word in a particular category. Each participant in turn says a word, but that word must begin with the final letter of the previous word. Once a word has been given, it cannot be repeated. If an opponent cannot give a word in the category, they fall out of the game. For example, with "animals" as the category,

Child 1: dog
Child 2: goldfish
Child 1: hippopotamus
Child 2: snake

... Write a function word_game() that accepts a list of words and returns the longest list of words that can be played in sequence. Your function may accept other input, but default values should be used so that it works if simply passed a list. Your program, while not graded for speed, should solve the following selection of 70 English Pokemon names (extracted from Wikipedia's list of Pokemon) in less than 3 minutes.

audino bagon baltoy banette bidoof braviary bronzor carracosta charmeleon
cresselia croagunk darmanitan deino emboar emolga exeggcute gabite
girafarig gulpin haxorus heatmor heatran ivysaur jellicent jumpluff kangaskhan
kricketune landorus ledyba loudred lumineon lunatone machamp magnezone mamoswine
nosepass petilil pidgeotto pikachu pinsir poliwrath poochyena porygon
porygonz registeel relicanth remoraid rufflet sableye scolipede scrafty seaking
sealeo silcoon simisear snivy snorlax spoink starly tirtouga trapinch treecko
tyrogue vigoroth vulpix wailord wartortle whismur wingull yamask

When you cut and paste this list, then parse it, make sure to check that it has 70 elements.

Attachment:- unixdict.rar

Reference no: EM131849650

Questions Cloud

Why do we need government anyways according to hobbes : Why do we need government anyways according to Hobbes, Locke and the founders? Explain briefly.
Identify and explain the rights of criminal suspects : Identify and explain the rights of criminal suspects
What steps will you take to develop a coordinated system : Describe how organizational culture and the use of performance criteria and standards affect the remaining components of a performance management system.
What is bureaucracy to max weber : What Max Weber bureaucracy better any type of organization? Agree ? Explain. Three pages detail with sources cited.
Write a recursive function called binary search : Write a recursive function called binary_search() that accepts as arguments a number - Write a function decimal() that accepts as input an integer denominator
Calculate the expected time for each activity : Calculate the expected time for each activity. Enter these values in the appropriate column in the table above.
Elimination of the articles of confederation : In your own words What connection (if any) did the Shays Rebellion have to the elimination of the Articles of Confederation in 1786-1787?
Introduce your paper with your previously crafted thesis : Identify three (3) specific groups that were affected by industrialization and provide two examples for each group describing how the group was affected.
Describe how demographic influences shape voting behavior : 1) According to Freud, a generalized anxiety disorder is most likely to result when 2) Describe how demographic influences shape voting behavior.

Reviews

len1849650

2/5/2018 6:07:13 AM

?Detailed Question: This homework is to be completed in Python 3. Please use basic code for code beginner! Add comments to your file (using #'s) and explain the output you get. Pay attention if the specification asks for a return or a print. Remember to document your code (purpose, input, output), as this will be an important part of your grade.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd