You are given four parameters, a, b, c, and d.
a and b represent the range of multipliers, while c and d represent the range of multiplicands.
If no parameters are given, assume default values of a=1, b=9, c=1, and d=9, with the additional constraint that and .
Your task is to generate a list of all possible products that can be obtained by multiplying any number from the range [a, b] with any number from the range [c, d].
Return this list of products as your solution, sorted based on the order in which the products are generated.
To generate the list of products, you should multiply a with c, a with c+1, ..., a with d, then a+1 with c, a+1 with c+1, ..., (a+1) with d, and so on, up to b with d.
In other words, you should loop through all possible combinations of multipliers and multiplicands in the following order:
a*c, a*(c+1), ..., a*d
(a+1)*c, (a+1)*(c+1), ..., (a+1)*d
...
b*c, b*(c+1), ..., b*d
Your function should be defined as follows:
def get_products(a=1, b=9, c=1, d=9):
# your code here
pass
You should assume that the function will be called with named arguments, and that the order of the arguments may not be consistent across function calls.
You only need to submit the functions get_products
. You should not read from stdin
or write to stdout
, e.g. calling print()
and input()
.
Input Specification
The sample input shows how your functions will be called.
Limits
Memory limits: 32MB.
Time limits: 1 second.
Ouput Specification
For each function call, you must return exactly what we asked for.
Test Set 1
Sample Case
Test Set 2
Sample Input
get_products(a=1,b=2,c=1,d=4)
Sample Output
[1, 2, 3, 4, 2, 4, 6, 8]
Comments