Python – Average of digit greater than K

PythonServer Side ProgrammingProgramming

When it is required to display average of digit greater than K, a simple iteration is used.

Below is a demonstration of the same −

Example

my_list = [11, 17, 25, 16, 23, 18]
print ("The list is :")
print(my_list)
K = 15
print("The value of K is ")
print(K)
my_count = 0
for index in my_list :
   if index > K :
      my_count = my_count + 1
print ("The result is :")
print(my_count)

Output

The list is :
[11, 17, 25, 16, 23, 18]
The value of K is
15
The result is :
5

Explanation

  • A list is defined and displayed on the console.

  • The value for K is defined and displayed on the console.

  • A counter variable is created.

  • The list is iterated over, and every element is compared with K.

  • If the element is greater than K, the count value is incremented by 1.

  • This is the output that is displayed on the console.

raja
Published on 08-Sep-2021 07:02:22
Advertisements