- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Average of digit greater than K
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.
Advertisements