Jul-29-2019, 01:11 PM
Hello everyone,
I am trying to find the number of times that a certain value appears in a string like [100, 100, 50, 20, 100, 30]. The user should insert a number (e.g. 100) and the program will give the answer (e.g. 3). I know how to do this using Count but I would like to solve the problem by simly using cyclic instruction like FOR and IF. Unfoltunately my code does not work. Do you have any idea on how to make this work? Thank you
I am trying to find the number of times that a certain value appears in a string like [100, 100, 50, 20, 100, 30]. The user should insert a number (e.g. 100) and the program will give the answer (e.g. 3). I know how to do this using Count but I would like to solve the problem by simly using cyclic instruction like FOR and IF. Unfoltunately my code does not work. Do you have any idea on how to make this work? Thank you
a = [100, 100, 50, 20, 100, 30] x = input("Insert number: ") c = 0 for i in range(len(a)): if x == a[i]: c = c + 1 print(c)