The starter code below creates three user input variables (floats), asking the user to enter a decimal number (note that we donβt use the word float in the prompt - end users donβt know what floats are!). Create a function header for a function that takes in three parameters and will calculate and return their average. Name the function something that makes sense and reflects what it will do. This function expects floating point numbers and returns a floating point number - make sure your header includes appropriate type annotations.
Inside the function, create a variable and assign to it the average value of the three passed in floats. Note: To calculate an average you take the sum of inputs and divide it by the number of inputs.
At the bottom of the script, call your newly defined function, passing in the three numbers. Assign the result of calling the function to a new variable.
In this level you will create a turtle program that will draw a whole bunch of squares that vary in size and colour. You are given starter code with a list of colours in it, and a turtle and a window. Follow the steps.
The starter code above contains two functions: the main function that creates the turtle and the world, and then has a for loop that iterates 10 times, and the move_random function that moves the turtle to random coordinates. Run the code to see what it does.
Note that on line 30, we call the move_random function and pass the turtle. The move random function has a turt parameter, and when it is called, that turt paramter is a reference variable that points at the turtle we created (dorsa). Inside the move_random function, when we give a turtle command we use the name βturtβ, but it is actually a reference to our dorsa turtle and causes dorsa to pick up her pen, move, and then put down her pen. Note also, that this means the move_random function can be called with another turtle, and it works no matter what name you give your turtle.
Look at line 34 in main. This is a commented out function call. Itβs commented out because the square function doesnβt exist yet. Your job is to create a square function that takes three parameters: a turtle, a number representing the size of square to draw, and a color. Define this function at the top of the script where you see the #TODO. You can choose whatever parameter names you want (itβs fine to use βturtβ for the turtle, just like in the move_random function). Inside this function, change the turtle to the color passed in, then write the code to draw a square, using the size value.
Define a new function called βcount_vowelsβ. This function should take a single parameter (you will pass in the string you just got from the end user). The function will return the number of vowels in the string. Add appropriate type annotations.
Once this is working, create a loop that iterates 3 times. Put the code that asks the user for a phrase and calls the count_vowel function inside that loop, so that we see the function getting executed multiple times with different values.