Python - 平均值大于 K
当需要显示大于 K 的平均数字时,使用简单的迭代。
以下是相同内容的演示 −
范例
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)输出
The list is : [11, 17, 25, 16, 23, 18] The value of K is 15 The result is : 5
说明
定义一个列表并显示在控制台上。
定义 K 的值并显示在控制台上。
创建一个计数器变量。
迭代列表,将每个元素与 K 进行比较。
如果元素大于 K,则计数值加 1。
这是显示在控制台上的输出。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP