7. Exercises 3

More exercises writing functions.
  1. Write a function at-most-250 that takes in a number and puts out the same number, or 250 if the number is larger than 250.

  2. Write a function small-0 that takes in two numbers and gives out the distance to zero of the number that is closest to zero on the number line. It should work with negative numbers as well.

  3. Write a function stuck-50-150 that takes in a number x and gives out x. Except if x is below 50, give an answer of 50. Also if x is more than 150, give an answer of 150.

  4. random-a: Write a function that gives a random number between -50 and 50.

  5. random-b: Write a function that gives a random even number 0-200.

  6. dice: Write a function that gives the total from randomly rolling two six sided dice.

  7. rstar: Write a function that makes a star with a random side length.

  8. dstar: Write a function that makes two stars next to each other, one should have a random side length and the other should have sides that are twice as long. (Note: make sure to write and test your non-random function first!)

  9. Challenge: make a star with a random number of sides. For the third number, the “step”, try (remainder 31 sides). You will want a helper function that knows the number of sides.

Last modified August 18, 2023: 2022-2023 End State (7352e87)