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

0

help i wrote a code and im pretty sure its giving me a correct answer and i submitted "CTFlearn{8291}" but still it says incorrect someone helps please

1

Check your statement.

2

i had the same problem but i finally figured it out! your total is the number of 0s divisible 3 AND the number of 1s divisible by 2. You dont want the total of both, numbers divisible by 2 and 3 arent counted. so add the number of lines divisible by 2 AND 3 and subtract it from your total

0

thanx for your explaination, it helped me solve this problem.

0