The program takes a number x - the length of the list. Create a list and populate it from the console. After that, the number y will be entered, which may or may not exist in the list. Your task is to print how many times the number y occurs in the list.
Example:
input:
5 # is the number x
0 # start of list
5
15
1
2 # end of list
5 # is the number y
output: 1
My attempt: But output is 0 Can you help me please?
x = int(input("x = "))
a = []
for _ in range(x):
numbers = int(input("number = "))
y = int(input("y = "))
counter = 0
for i in a:
if y in a:
counter = 1
print(counter)
CodePudding user response:
x = int(input("x = "))
a = []
for _ in range(x):
number = int(input("number = "))
a.append(number) # add this line
y = int(input("y = "))
counter = 0
for i in a:
if i == y: # change condition here
counter = 1
print(counter)