英文:
write a python program to input a number and count the occurrence of a given number in a given list
问题
我需要一个答案这个问题
你们可以帮我吗
我尝试过这个
lst=[]
n = int(input("输入元素的数量:"))
for i in range(0, n):
ele = int(input())
lst.count(ele)
print(lst)
无法得到问题的答案
英文:
I need an answer for this question
can u guys hel me
I tried this
lst=[]
n = int(input("Enter number of elements :"))
for i in range(0, n):
ele = int(input())
lst.count(ele)
print(lst)
cant get answer for the question
答案1
得分: 1
这似乎是一个非常直接的解决方案。您只需遍历您给定的列表,并将每个元素与您想要检查的数字进行比较。只需在条件满足的情况下增加计数。
given_lst = [1, 2, 3, 4 , 5, 65, 6, 4, 5, 4 , 4, 6, 2]
num = int(input("输入一个数字: "))
count = 0
for number in given_lst:
if number == num:
count += 1
print(f"总出现次数: {count}")
英文:
Seems very straightforward solution to me. You just need to loop through your given list and compare each element with the number you want to check. Just increment the count in case of if condition satisfies.
given_lst = [1, 2, 3, 4 , 5, 65, 6, 4, 5, 4 , 4, 6, 2]
num = int(input("Enter a number: "))
count = 0
for number in given_lst:
if number == num:
count += 1
print(f"Total occurrence: {count}")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论