for 循环-计算在列表中某数值或字符串出现的次数
第一步,count=0
第二步,列出列出列表里面有啥:nums=[数值1,数值2]或nums=[字符串1,字符串2]
第三步,for循环遍历列表:for num in nums:if num==你要计算次数的数值:count
=count+1
最后一步,print(count)
count=0
nums=['a','b','c','a']
for num in nums:
if num=='a':
count=sount+1
print(count)
for 循环-计算在列表中某数值或字符串出现的频率
第一步,计算在列表中某数值或字符串出现的次数
第二步,计算列表长度
第三步,次数除以列表长度
count=0
nums=['a','b','c','a']
for num in nums:
if num=='a':
count=count+1
l=len(nums)
radio=float(count/l)
print(radio)
for 循环-找出区间中的偶数
for i in range(1,101):
if (i%2==0):
print(i)