This week, we will be playing with functions. Take a look at what you’re given in the file below. IT 11 11 FUNCTION: getMonth ( dateString : string ) -> string Takes in a dateString of the form “DD/MM/YYYY” and returns the full name of the the month MM. e.g. “17/01/2007” returns “January”. Hint: Use a monthNames list. Args : @param dateString string of date in the form “DD/MM/YYYY” Returns: @return String holding the name of the month represented by MM of the dateString The first bit gives a brief description about the general intention of the function. Here we can see that the function is going to read in a data string of the form “DD/MM/YYYY” (where DD represents 2-digit day, MM represents a 2-digit month and YYYY a 4-digit year). Hints & Tips: The first thing to get used to is the template for how the function details are presented within comments. You will note that, in this PoD and in your assignment, your methods have comments before them to guide you. So that you can get used to this format, I’ll step you through it. The @param tag gives the parameter (or, other times, parameters) that will hold the arguments expected by the function. If more than one parameter is given, they are expected in the order as presented. For instance, if you saw IT IT FUNCTION: getPersonDetails ( name : string, age : int) Args : @param name String holding full name @param age integer age of person Returns: @return void you can assume that the getPersonDetails function would expect the parameters name (string) and age (int) in exactly that order. The @return tag specifies the type and details of what the function will return. In the getPersonDetails example, we see that void is specified. In that case, there would be no return value expected In our example, we can see that our function should return a “String holding the name of the month represented by “MM” of the dateString. That is, we should expect that if MM is “01”, the function returns “January” and if MM is “12”, the function returns “December”. Details Input • Input has been handled for you and your function will be given a date string of the form “DD/MM/YYYY”. Processing • Complete the function as described in the comments. Output Output consists of the month name that is returned from your function. Sample input/output: Function argument Function output 24/07/2007 July 17/01/1983 January 28/08/1985 August We were unable to transcribe this image39 40 FUNCTION: main() 41 42 – def main() : dateString = input() 44 month= getMonth(dateString), 43 46 print( month ) return 48 49 main() Show transcribed image text This week, we will be playing with functions. Take a look at what you’re given in the file below. IT 11 11 FUNCTION: getMonth ( dateString : string ) -> string Takes in a dateString of the form “DD/MM/YYYY” and returns the full name of the the month MM. e.g. “17/01/2007” returns “January”. Hint: Use a monthNames list. Args : @param dateString string of date in the form “DD/MM/YYYY” Returns: @return String holding the name of the month represented by MM of the dateString The first bit gives a brief description about the general intention of the function. Here we can see that the function is going to read in a data string of the form “DD/MM/YYYY” (where DD represents 2-digit day, MM represents a 2-digit month and YYYY a 4-digit year). Hints & Tips: The first thing to get used to is the template for how the function details are presented within comments. You will note that, in this PoD and in your assignment, your methods have comments before them to guide you. So that you can get used to this format, I’ll step you through it. The @param tag gives the parameter (or, other times, parameters) that will hold the arguments expected by the function. If more than one parameter is given, they are expected in the order as presented. For instance, if you saw
IT IT FUNCTION: getPersonDetails ( name : string, age : int) Args : @param name String holding full name @param age integer age of person Returns: @return void you can assume that the getPersonDetails function would expect the parameters name (string) and age (int) in exactly that order. The @return tag specifies the type and details of what the function will return. In the getPersonDetails example, we see that void is specified. In that case, there would be no return value expected In our example, we can see that our function should return a “String holding the name of the month represented by “MM” of the dateString. That is, we should expect that if MM is “01”, the function returns “January” and if MM is “12”, the function returns “December”. Details Input • Input has been handled for you and your function will be given a date string of the form “DD/MM/YYYY”. Processing • Complete the function as described in the comments.
Output Output consists of the month name that is returned from your function. Sample input/output: Function argument Function output 24/07/2007 July 17/01/1983 January 28/08/1985 August
39 40 FUNCTION: main() 41 42 – def main() : dateString = input() 44 month= getMonth(dateString), 43 46 print( month ) return 48 49 main()
Expert Answer
Answer to This week, we will be playing with functions. Take a look at what you’re given in the file below. IT 11 11 FUNCTION: get…