Not sure what\'s going on here ..in Python In this assignment, you may Make sure
ID: 3702472 • Letter: N
Question
Not sure what's going on here ..in Python
In this assignment, you may Make sure your name is in a comment at the top of the file. only use the sys, strings, copy and time modules. Your goal is to create a decorator that extends a function with some logging statements. The logging decorator must be called log and must be defined in the module log. decorator.py. The decorator may optionally take a single argument that indicates the file to which the statements should be appended. If no argument is provided, the statements are written to stdout. If the filename provided cannot be opened for whatever reason, logging should be directed to stdout. The logging decorator should extend the function by printing the following items: 1. The name of the function being called. (Hint: Make use of the_nameattribute available on every function object). 2. A list of the arguments supplied to the function as well as the type of the argument. If no arguments are supplied, you must report this. You might want to make use of_name here as well! 3. The output of the function. 4. The execution time of the function (elapsed wall clock time) in seconds. The time should be rounded to 5 decimal places. 5. The return value and the type of the return value. Note that even when multiple values are returned, the return value is a single tuple object. If there is no return value, you must report this. To demonstrate the behavior of the log decorator, take a look at the following example log test.py, which defines (but does not show) the log decorator alog () def factorial(*num list) results- for number in num list: res-number for i in range (number-1,0,-1) resi*res results.append (res) return resultsExplanation / Answer
Here the sequence of functions are executed one after the other along with their execution time
Let us closely look at function call
factorial(4,5)
waste_time("one",2,"3")
gcd(15,9)
print_hello()
print_goodbye()
Let us now check the corresponding output
so first is showing that the
factorial function is called
having two arguments 4 and 5 of type of Integer
Its returning the factorial of each number in a list i.e. [24,120]
Also it is shwoing the execution time
Next the print_hello function is called
it is having no arguments
just printing Hello
Also it is showing the execution time along with it that it is not returning any value.
Next the print_goodbye fuction is called
It is having no arguments
just printing Goodbye
Also it is showing the execution time along with it that it is not returning any value.
Next the waste_time function is called
here 3 arguments are passed of which one is integer and the other two is string type
It is just executing some idle time
returning the arguments value in the form of tuple
Last of all the gcd function is called.
Two arguments are passed 15 and 9 of type integer
this function is calculating the GCD of the two numbers
it is printing the gcd of the number 15 and 9 and that is 3
also it is showing the execution time
And it is returning the value of type int.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.