Place your order now for a similar assignment and have exceptional work written by our team of experts, At affordable rates
Now that we are writing functions, we expect to see function header comments in addition to the program header. We would like you to follow the convention below for writing your function headers (called ″docstrings″. Please note that this is different than what the book shows. Our method follows the suggested styling found in the pep 8 Python style guide for docstring conventions. A docstring, short for ″documentation string″ is a string literal that serves as documentation of the program. Every function should have a docstring that describes what the function′s purpose is, anything that might be unique about the coding of the function, a list and desсrіption of the parameters and an indication of what the function returns. Each of your functions should have a docstring that looks something like this. (Take note of where the docstring is – it is after the function definition, not before like in the textbook).
def myFunction(a, b):
This function adds the values of the two parameters, a and b, and returns the result.
Parameters: a, b – integer values representing some interesting things
Return Value – the sum of a and b – an integer
From this point on, all of your programs will be written using functions. All the code (except for a few exceptions such as import statements or global variables) should be put into a function. A function should have one purpose and should be named accordingly. For instance, if you write a function to calculate the area of a triangle, you might name it ″calculateArea()″ or ″calculateTriangleArea()″ but you would not name it ″triangle()″ or ″a()″ or some other non-meaningful name. You should be able to determine from the name of the function what it′s purpose is. And the function should ONLY carry out that specified functionality. A function called calculateArea() should not ask the user for the values that it should use to calculate the area (those should be provided via the parameters) and it also should not calculate, say, the perimeter of the triangle as well as the area.
Write all the following functions in the same python file — it will be one single program.
1) Write a function that prints the following poem but customizes it to have a different person′s name each time. (I have used my name in the sample to show you where the name should be).
Loops were crazy,
What are functions about?
Wendy, you can do this
Just stick it out!
Your function needs to have a parameter and will return nothing. The function must not ask the user for input.
2) Write a function that takes two integers as parameters, n and m (you can call them n and m in your program). The function will return the product of the square of each of the values from n to m (inclusive). For example, n＝5, m＝8, the function returns the result of:
5 * 5 * 6 * 6 * 7 * 7 * 8 * 8
which would be 2822400. Your function should ensure that n is greater than m and that there will be no more than 4 digits involved in the calculation (ie. the difference between n and m is no more than 3). If the criteria are not satisfied, the function returns 0. There should be no print statements in this function nor should the function ask the user for any input.
3) Write a function that translates Canadian dollars to Chinese currency (Yuan) assuming that each Canadian dollar is worth 5.19 Yuan. Your function should take appropriate parameters and return the converted amount. There should be no print statements nor should the user be asked for any input in this function.
4) Create a menu that will allow the user to choose to run any of the functions that you have written. The menu will display the options and allow the user to chose a number from 1-3, each corresponding to a function. You will need a fourth option to allow the user to end the program. You should check to ensure that the user has entered a valid number, and if not, continue to prompt him/her for valid input. Use the user′s choice to run the function. Make your program user friendly — tell the user which function they have chosen to run and what the output is (if any). You will need to ask the user for input before running the functions. Do this after they make a selection from your menu.