Question: Using Python 10.19 Write a recursive method numOnes() that takes a nonnegative integer n as input and returns the number of 1s in the binary

Using Python

10.19 Write a recursive method numOnes() that takes a nonnegative integer n as input and returns the number of 1s in the binary representation of n. Use the fact that this is equal to the number of 1s in the representation of n//2 (integer division), plus 1 if n is odd. >>> numOnes(0) 0 >>> numOnes(1) 1 >>> numOnes(14) 3

10.23 Develop a recursive function tough() that takes two nonnegative integer arguments and outputs a pattern as shown below. Hint: The first argument represents the indentation of the pattern, whereas the second argumentalways a power of 2indicates the number of *s in the longest line of *s in the pattern. >>> f(0, 0) >>> f(0, 1) * >>> f(0, 2) * ** *

10.24 Write a recursive method base() that takes a nonnegative integer n and a positive integer 1 < b < 10 and prints the base-b representation of integer n. >>> base(0, 2) 0 >>> base(1, 2) 1 >>> base(10, 2) 1010 >>> base(10, 3) 1 0 1

10.26 Implement function anagrams() that computes anagrams of a given word. An anagram of word A is a word B that can be formed by rearranging the letters of A. For example, the word pot is an anagram of the word top. Your function will take as input the name of a file of words and as well as a word, and print all the words in the file that are anagrams of the input word. In the next examples, use file words.txt as your file of words. >>> anagrams('words.txt', 'trace') File: words.txt crate cater react

10.28 In this problem, you will develop a function that crawls through linked files. Every file visited by the crawler will contain zero or more links, one per line, to other files and nothing else. A link to a file is just the name of the file. For example, the content of file file0.txt is: file1.txt file2.txt The first line represents the link o file file1.txt and the second is a link to file2.txt. Implement recursive method crawl() that takes as input a file name (as a string), prints a message saying the file is being visited, opens the file, reads each link, and recursively continues the crawl on each link. The below example uses a set of files packaged in archive files.zip. File: files.zip >>> crawl('file0.txt') Visiting file0.txt Visiting file1.txt Visiting file3.txt Visiting file4.txt Visiting file8.txt Visiting file9.txt Visiting file2.txt Visiting file5.txt Visiting file6.txt Visiting file7.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!