1
Program that has only one function, besides the main program, that will receive as parameters an integer number x, a sequence of integers L and a natural n, representing an item x that must have quantified its occurrences in the sequence L of size n.
The function should return a natural value indicating the amount of occurrences of x in L.
Entree:
(a) the first line of the entry contains the searched item x;
(b) the second line of the entry contains the sequence size n;
(c) the next n lines represent the items that make up the sequence.
7
6
70
71
72
73
7
54
Exit:
(a) the main program shall print a natural value indicating the amount of occurrences of x in L according to the value returned by the function.
1
Code created until then:
X = input()
N = int(input())
L = [0]
Quantidade = 0
for i in range(len(L),N):
if X [i]==X:
Quantidade += 1
Novo = input()
L.insert(0,Novo)
print(Quantidade)
I’m not quite understand the implementation of this program in list, the above code is not working.
It is that in fact I would like to do as follows, the numbers that are typed by the user within this for loop, were stored in a list, after they are in the list, for example: [70,71,72,73,7,54], find how many times the number "7" occurs within that list.
– user186294
Summarizing, after the user insert the values "X and N" all the values typed inside the for loop, by the user, would be inserted in a list, after insertion, there would be the location of how many times the number "X" of the beginning of the program occurs in the created list.
– user186294
@I updated the answer
– hkotsubo
Thank you very much! Your explanations have helped me a lot to better understand the functioning of the list.
– user186294