Combine Nums¶
We wish to combine two given, non-empty, digits only, strings into a new, digits only, string.
Notice from the examples that the two given string do not necessarily have the same length.
You are required to deliver the following function in the module nums_module (file nums_module.py):
- nums_combine(n1, n2)¶
such that
given n1, n2
strwith non-empty, not necessarily with the same length, sequences of digits.returns a
strgenerated by taking the integer part of the mean of the digits aligned in the same position of n1 and n2. In case a position is exists only in one of the strings (because the other one is shorter) then that digit is taken.
For instance, nums_combine of '111', '78901' should produce '44501'. The first three digits correspond each to the integer mean of the two digits in the same position in n1 and n2. Namely: 4 is the int mean of 1 and 7, 4 is also the int mean of 1 and 8, and 5 is the int mean of 1 and 9. Finally '01' is the tail of the longest one.
See more examples:
>>> nums_combine('111', '78901') '44501' >>> nums_combine('21458', '51279') '31368' >>> nums_combine('12345', '00000') '01122' >>> nums_combine('00000', '00000') '00000' >>> nums_combine('21458', '') '21458'
Doctests are available in the nums_combine.test file.