Write a function ones_and_tens_digit_histogram(numbers) that takes as input a list of numbers and produces as output a list of 10 numbers. Each element of the result indicates the frequency with which that digit appeared in the ones place or the tens place in the input. here is an example call and result: Call: ones_and_tens_digit_histogram([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]) Return: [0.21428571428571427, 0.14285714285714285, 0.047619047619047616, 0.11904761904761904, 0.09523809523809523, 0.09523809523809523, 0.023809523809523808, 0.09523809523809523, 0.11904761904761904, 0.047619047619047616] In this example call, the index 1 of the list contains the element 0.14285714285714285 because the value 1 appears in 14.285714285714285% of the ones or tens digits of the given numbers. In a number that is less than 10, such as 3, the tens place is implicitly zero. That is 3 must be treated as 03. Your code should treat the tens digits of these values as zero. Hints: To get the ones and tens digits of a number, review the % and // operators. For example, what is the result of 31 % 10? Why? What is the result of 31 // 10? Why? What about 4 // 10 and 0 % 10? In order to calculate an average for digit i, you will need to know the number of times i appears in the ones or tens digit — for the numerator — and the total number of digits — for the denominator. What should the denominator be? Make sure your averages aren't off by a factor of two. To generate a list of the same number X with length N, you can use the syntax [X] * N Python PRogramming please
Write a function ones_and_tens_digit_histogram(numbers) that takes as input a list of numbers and produces as output a list of 10 numbers.
Each element of the result indicates the frequency with which that digit appeared in the ones place or the tens place in the input. here is an example call and result:
Call: ones_and_tens_digit_histogram([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765])
Return: [0.21428571428571427, 0.14285714285714285, 0.047619047619047616, 0.11904761904761904, 0.09523809523809523, 0.09523809523809523, 0.023809523809523808, 0.09523809523809523, 0.11904761904761904, 0.047619047619047616]
In this example call, the index 1 of the list contains the element 0.14285714285714285 because the value 1 appears in 14.285714285714285% of the ones or tens digits of the given numbers. In a number that is less than 10, such as 3, the tens place is implicitly zero. That is 3 must be treated as 03. Your code should treat the tens digits of these values as zero.
Hints:
- To get the ones and tens digits of a number, review the % and // operators. For example, what is the result of 31 % 10? Why? What is the result of 31 // 10? Why? What about 4 // 10 and 0 % 10?
- In order to calculate an average for digit i, you will need to know the number of times i appears in the ones or tens digit — for the numerator — and the total number of digits — for the denominator. What should the denominator be? Make sure your averages aren't off by a factor of two.
- To generate a list of the same number X with length N, you can use the syntax [X] * N
Python PRogramming please
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images