while True:
listfilter = list()
liststart = list()
n1 = len(liststart)
n2 = len(listfilter)
print(The program that calculates the number of integers excluding multiple of 3 and multiple of 5. Continue to enter integers one by one. Type 0 to exit.")
ans = input()
if int(ans) != 0 :
if int(ans)%3 == 0 or int(ans)%5 == 0 :
listfilter.append(ans)
else:
liststart.append(ans)
else:
print("Total", n1", integers are entered, and the number of integers excluding multiples of 3 and 5 is "n1-n2".")
break
I wrote a code that counts the number of integers excluding multiples of 3 and 5, but when I enter the integer, I ask again, and when I press 0, I get out of the repetition, and even the last print, but I couldn't attach the integers to the list, so the number of lists is recognized as zero. What kind of mistake would he make?
python
There are some parts that were different from the first question to be called mistakes.
Please keep that in mind.
listfilter = list()
liststart = list()
while True:
The program that calculates the number of integers excluding multiple of str = ''3 and multiple of 5. Continue to enter integers one by one. Enter 0 to exit.
>> '''
ans = input(str)
liststart.append(ans)
if int(ans) != 0 :
if int(ans) % 3 == 0 or int(ans) % 5 == 0 :
listfilter.append(ans)
else:
n1 = len(liststart)
n2 = len(listfilter)
print(f"total {n1} integers are entered, and the number of integers excluding multiples of 3 and 5 is {n1-n2}.")
break
© 2024 OneMinuteCode. All rights reserved.