Question

A Hawaiian earring is a shape consisting of several circles, all tangent at a point: You can make Python draw a circle with the function turtle.circle, which takes a single integer argument specifying the circles size (remember to import turtle first). Task 4 Define a global variable called earring ratio, and assign it the value . You can experiment with changing this value later

Task 5

Write a function called “earring_iter” that takes two integer arguments, size and count. This function should use a (for or while) loop to draw a Hawaiian earring containingcount-manycircles,wherethefirstcircledrawnhassizesize,andeachsubsequent circle has size earring_ratio times the size of the previous circle.

Here is a recursive specification for drawing a Hawaiian earring of a given size:

• To draw a Hawaiian earring of a given size with zero hoops, do nothing.

• To draw a Hawaiian earring of a given size with a positive number of hoops, draw a circle of the given size, then draw a Hawaiian earring with one fewer hoops, of size earring_ratio times the current size.

Task 6

In the recursive specification above, identify the base case and recursive case. Then write a recursive function called “earring_rec” that implements the specification. Your recursive function should not contain any loops at all and should behave just like earring_iter.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import turtle

earring_ratio = 3/4

def earring_iter(size,count):
   x = turtle.Turtle()
   while(count):
       x.circle(size)
       size = size*earring_ratio
       count = count - 1
   turtle.done()

def earring_rec(size,count):
   x = turtle.Turtle()
   if(count == 0):
       return
       turtle.done()
   else:
       x.circle(size)
       earring_rec(size*earring_ratio,count-1)

Add a comment
Know the answer?
Add Answer to:
Task 5 Write a function called “earring_iter” that takes two integer arguments, size and count. This...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Write a function/method called CheckHash: takes two arguments, an array and an integer count n....

    Java Write a function/method called CheckHash: takes two arguments, an array and an integer count n. The function computes the exclusive OR of the hashcodes (https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode--) of the first n strings in the array (result type int).

  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

    Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...

  • 1. Write a Lisp function called piece which takes a single argument x and implements the followin...

    1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...

  • Python - Write a function called create_basic_pattern(background_colour, size)

    Write a function called create_basic_pattern(background_colour, size) which takes a background colour code and an integer as parameters and returns a list of strings. The list represents the pattern of a pixel art pattern. For example, consider the following code fragment:pattern \(=\) create_basicThen the function should create a list of strings. The size of the list is 8 . Each element is a string with 8 'y' characters:

  • d printAllIntegers () Write a C++ program that defines and tests a function largest(....) that takes...

    d printAllIntegers () Write a C++ program that defines and tests a function largest(....) that takes as parame- ters any three integers and returns the largest of the three integers. Your output should have the same format and should work for any integers a user enters Desired output: Enter three integers: 6 15 8 The largest integer is: 15 7.3 Recursive Functions Write a program that uses a function sum(int) that takes as an argument a positive integer n and...

  • In C: Write a function "MinMax" that takes as an argument an integer array, an integer...

    In C: Write a function "MinMax" that takes as an argument an integer array, an integer for the size of the array, and two integer pointers. The function should print nothing and return nothing but change the value of the first pointer to the minimum value in the array and change the value in the second pointer to the max value in the array.

  • In Python 3 (2.5 pts] Write the recursive function thirtyTwos(n) that takes an integer greater or...

    In Python 3 (2.5 pts] Write the recursive function thirtyTwos(n) that takes an integer greater or equal to 0 and returns an integer that represents the number of times that a 2 directly follows a 3 in the digits of n. Hint: The % and // operations from sumDigits could be helpful here >>> thirtyTwos (132432601)

  • Given an array and a starting position write a function replaceFromN, that takes an integer array...

    Given an array and a starting position write a function replaceFromN, that takes an integer array 'array', the size of the array size and a starting positions 'n' as parameters and replaces the elements starting from that index onward with the sequence 1,2,3,... The function returns nothing. void replaceFromN(int array[], int size, int n) For example, given array= {15,12,4,9,2,3} n =2 the function should modify array to be {15,12,1,2,3,4}

  • Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount,...

    Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount, an integer specifying the number of “buckets” to return and numberLs, a list of numbers ) buckets should split the range of values in numberLs into bucketCount sub-ranges. Specifically buckets should return a list-of-lists of length bucketCount. Each list in the returned list-of-lists represents a “bucket”. Each bucket should contain the numbers from numberLs whose values are greater than or equal to min(numberLs) +...

  • Write a C++ program that contains a function called swapNums. This function takes two integer parameters,...

    Write a C++ program that contains a function called swapNums. This function takes two integer parameters, swaps them in memory, and outputs the results (there is nothing to return). In main, ask the user to enter two different numbers, output them as entered (step 1), call the function swapNums() which will output the numbers swapped (step 2), and then output the values again in main (step 3). You should have three sets of output. Sample run (10 and 5 were...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT