Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We often create basic functions to help distinguish areas of code that require re-use or provide helpful calculations or manipulation of variables. Steps 1.
We often create basic functions to help distinguish areas of code that require re-use or provide helpful calculations or manipulation of variables. Steps 1. Create a new file and name it appropriately. (Remember to include .py otherwise VSCode will not interpret it as a python file) 2. Write a function called circlesInRectangle which takes three parameters: length, width (of a rectangle) and area (of a circle). 3. This function should return the number of circles that can fit into a rectangle. 4. Operations performed by this function should be consistent with the following formula: number of Circles = (length x width) area Task 2: Basic Functions Cont. (1 mark) Steps 1. Write a function named areaOfCircle which takes one parameter: radius (of a circle). 2. This function should return the area. Note: You will need to utilise Pi (r) which is included in the "math" package. It is poor coding practice to import entire packages. You should only import what you need. 3. At the beginning of your Python file, insert the code below to allow access to the value. from math import pi 4. Operations performed by this function should be consistent with the following formula: area = pi x radius Task 3: Calling Functions (1 mark) Calling a function within another function is common practice in programming. You can create smaller, more manageable functions to be utilised within other areas of your code. Steps 1. Modify the function "circlesInRectangle" to make use of the function "areaOfCircle". Note: Make a copy of your current method to show your supervisor at the end of class. You can comment it out so that the IDE does not show an error. 2. You will need to change the area parameter to radius. 3. When calling your formula in code, replace area with your method and pass it the radius.
Step by Step Solution
★★★★★
3.41 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
Task 1 I have created a new file called basicfunctionspy and written ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started