@extends('template') @section('title') Lab 12: Part 0: Warm up @stop @section('content') # Lab 12: Part 0: Warm up ## Paper worksheet [Click here for worksheet](https://docs.google.com/document/d/1gbbPIuLKEHtOxHPC3vp5IaNJmCnpU_4-uAVd5Kglv8g/edit?usp=sharing) ## Part 0. chop ```py def chop(num): if num > 0: print(num) chop(num//2) # integer division ``` Given the function `chop` above, predict what is printed: ```py >>> chop(0) >>> chop(6) >>> chop(15) ``` Make your predictions and discuss with your partner before running the code. ## Part 1. fade ```py def fade(s): if len(s) > 0: print(s) fade(s[1:]) ``` Given the function `fade` above, predict what is printed: ```py >>> fade('') >>> fade('hat') >>> fade('scarf') ``` Make your predictions and discuss with your partner before running the code. ## Part 2. grow ```py def grow(s): if len(s) > 0: grow(s[1:]) print(s) ``` Given the function `grow` above, predict what is printed: ```py >>> grow('') >>> grow('hat') >>> grow('scarf') ``` Make your predictions and discuss with your partner before running the code. {{-- --}} ## [OPTIONAL] Part 3. both ```py def both(s): if len(s) > 0: print(s) both(s[1:]) print(s) ``` Given the function `both` above, predict what is printed: ```py >>> both('hat') ``` {{-- commenting out Term 3 --}} {{-- ## [OPTIONAL] Part 4: English plan Come up with a plan in English to recursively solve this problem. A function called `row(number, size)` draws a horizontal row of number squares of size `size`. This function must be **recursive** and maintain a position and heading invariant*. Assume you are given a function `square(size)` that draws a square with side `size`. *what does this mean? Two separate turtle drawings: 1) On the left, the result of row(5, 20) shows 5 red squares in a horizontal row with each square side length 20 and 2) On the right, the result of row(3, 30) shows 3 red squares in a horizontal row with each square having side length 30. The turtle is displayed in both drawings located in the lower left corner of the leftmost square. --}} {{-- --}} {{-- --}} @include('/labs/lab12/_toc') @stop