Assume that this function receives a string that only has digits and that it has at least a '0'.
The function should treat each digit as a separate number and should calculate the minimum, maximum and average of the digits, considering all the digits from position 0 until but not including the first digit with value '0'. The result should be a string containing the three values: that is, minimum, maximum and average of those numbers separated by one hyphen ('-'). The average should be calculated with fractional part.
For example minMaxAvg('325408214') should return '2-5-3.5' because 2 is the minimum among 3,2,5,4 ; 5 is the maximum among 3,2,5,4 and 3.5 is the average of 3,2,5,4.
- Code: Select all
def minMaxAvg (inputs):
while inputs[i] != '0':
new_string += inputs[i]
i += 1
mi = int(min(new_string))
ma = int(max(new_string))
total = 0
for i in range(len(new_string)):
total += int(new_string[i])
average = int(total)/int(len(new_string))
answer = int(mi) + "-" + int(ma) + "-" + int(average)
I can't get the answer, can someone please help?