you are provided with 3 numbers input 1 input 2 input 3 each of these are four digit numbers within range
and
i.e
you are expected to find the key using below formula
key= smallest digit in thousands place of all three numbers
smallest digit in the hundred place of ,all three numbers
smallest digit in the tens place of all three numbers
smallest digit in the units place of all three numbers
assuming that 3 numbers are passed to given function,complete the function to find and return key
Answers
def key_gen(n1, n2, n3):
digits_list = [list(map(int, str(n1))), list(map(int, str(n2))),
list(map(int, str(n3)))]
min_thousands = str(min([digits[0] for digits in digits_list]))
min_hundreds = str(min([digits[1] for digits in digits_list]))
min_tens = str(min([digits[2] for digits in digits_list]))
min_units = str(min([digits[3] for digits in digits_list]))
return int(min_thousands + min_hundreds + min_tens + min_units)
print("Key:", key_gen(9614, 3920, 5588))
Answer:
def key_gen(n1, n2, n3):
digits_list = [list(map(int, str(n1))), list(map(int, str(n2))),
list(map(int, str(n3)))]
min_thousands = str(min([digits[0] for digits in digits_list]))
min_hundreds = str(min([digits[1] for digits in digits_list]))
min_tens = str(min([digits[2] for digits in digits_list]))
min_units = str(min([digits[3] for digits in digits_list]))
return int(min_thousands + min_hundreds + min_tens + min_units)
print("Key:", key_gen(9614, 3920, 5588))