Concept explainers
Under your module imports, paste the following definitions:
(define WIDTH 300)
(define HEIGHT 160)
(define ES (empty-scene WIDTH HEIGHT))
(define (next-size s) (/ s 2))
Next, write a tail-call recursive function called circles. This function should take two numbers, x and size, and a Scene scn. If size is less-than or equal to 2, then your function returns the scn unchanged (base case). Otherwise, your function should place a circle in the Scene that results from a recursive call to circles with x shifted by (+ size (next-size size)), a new size of (next-size size), and using the original Scene. After evaluating (circles 100 48 ES), your function should output this image of five blue circles, in this order, with the first circle at (x,y) coordinate position (100, 80):
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- 1) Write a recursive void function that has one parameter that is a positive integer and that writes out that number of asterisks (*) to the screen, all on one line. How do I do this in python?arrow_forwardPlease answer quick in pythonarrow_forward‘Write a function nesting(), which takes an arbitrary number of parameters, and returns a list containing the arguments. Write another function unnesting(), which takes a list L as the parameter and retums a 1D list. Notice that, you should be able to use loops to solve thisproblem and should not use recursive functions (which we will not cover in this course). ‘Write assertions to test the two functions.For example nesting(1, nesting(2, 3, nesting(4, 5, [6])), [7, 8], 9)unnesting([1, [2, 3, [4, 5, [6]]], [7. 8], 9]) (1, [2, 3, [4, 5, [6]]], [7, 8], 9][1, 2,3, 4, 5, 6, 7, 8 9]arrow_forward
- Objective: Practice writing recursive functions in python3 Make the five recursive functions described below in python3 by using the starter code recursive_functions.py. For each function, figure out how to solve it conceptually : write down the base case (when recursion stops) and how each recursive function-call moves towards the base case. The functions should not print anything (except you may add temporary print statements to help debug them). You can test your program by using the provided program test_recursive_functions.py. Don't edit the test program. Put it into the same directory (folder) with your recursive_functions.py and run it. It will import your functions as a module, test your functions, and tell you when each function is returning correct results. 1. Factorial In math, if you have a number n, the factorial function (written n!) computes n x (n-1) x (n-2) x (n-3) x ... x 1. For example: 0! is defined to be 1 1! = 1 2! = 2 x 1=2 3! = 3 x 2 x 1=6 4! = 4 x 3…arrow_forwardWrite code to complete raise_to_power(). Note: This example is for practicing recursion; a non-recursive function, or using the built-in function math.pow(), would be more common.Sample output with inputs: 4 24^2 = 16 def raise_to_power(base_val, exponent_val): if exponent_val == 0: result_val = 1 else: result_val = base_val * ''' Your solution goes here ''' return result_val user_base = int(input())user_exponent = int(input()) print('{}^{} = {}'.format(user_base, user_exponent, raise_to_power(user_base, user_exponent)))arrow_forwardPYTHON Code your own Python function to solve Ax=b. Add a documentation string section to be used with the Python function help() function. Demonstrate the function is correctly implemented, and explain your testing approach.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education