Question
Using Python 10.22 Youre visiting your hometown and are planning to stay at a friends house. It just happens that all your friends live on
Using Python
10.22 Youre visiting your hometown and are planning to stay at a friends house. It just happens that all your friends live on the same street. In order to be efficient, you would like to stay at the house of a friend who is in a central location in the following sense: the same number of friends, within 1, live in either direction. If two friends houses satisfy this criterion, choose the friend with the smaller street address. Write function address() that takes a list of street numbers and returns the street number you should stay at. >>> address([2, 1, 8, 5, 9]) 5 >>> address([2, 1, 8, 5]) 2 >>> address([1, 1, 1, 2, 3, 3, 4, 4, 4, 5]) 3
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
10.32 The Lvy curves are fractal graphical patterns that can be defined recursively. Like the Koch curves, for every nonnegative integer n > 0, the Lvy curve Ln can be defined in terms of Lvy curve Ln1; Lvy curve L0 is just a straight line. Figure 10.17 shows the Lvy curve L8. (a) Find more information about the Lvy curve online and use it to implement recursive function levy() that takes a nonnegative integer n and returns turtle instructions encoded with letters L, R and, F, where L means rotate left 45 degrees, R means rotate right 90 degrees, and F means go forward. >>> levy(0) 'F' Lvy curve L8. >>> levy(1) 'LFRFL' >>> levy(2) 'LLFRFLRLFRFLL' (b) Implement function drawLevy()) so that it takes nonnegative integer n as input and draws the Lvy curve Ln using instructions obtained from function levy().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started