Simple Programming
30 points Easy

Can you help me? I need to know how many lines there are where the number of 0's is a multiple of 3 or the numbers of 1s is a multiple of 2. Please! Here is the file: https://mega.nz/#!7aoVEKhK!BAohJ0tfnP7bISIkbADK3qe1yNEkzjHXLKoJoKmqLys

Flag
Rating 4.41
5
4
3
2
1

Discussion

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0
Protected
1

Open the file

with open("data.dat", 'r') as file: # Read all lines from the file lines = file.readlines()

Initialize a counter for lines meeting the conditions

count = 0

Iterate through each line in the list of lines

for line in lines: # Strip whitespace from the line and check if it's not empty if line.strip(): # Count the occurrences of '0' and '1' in the line count_0 = line.count('0') count_1 = line.count('1')

    # Check if the count of 0's is a multiple of 3 or the count of 1's is a multiple of 2
    if count_0 % 3 == 0 or count_1 % 2 == 0:
        # Increment the counter if the condition is met
        count += 1

Print the count of lines meeting the conditions

print(count)

1

Remember OR is important, this will impact the logic of ur code, ez challenge

1

here's my solution python count = 0; for line in open("data.dat", "r").readlines(): zero = 0 one = 0 for i in line: if i == '0': zero += 1 elif i == '1': one += 1 if zero % 3 == 0 or one % 2 == 0: count += 1 print(count)

0