Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For loops not running PSET6 DNA CS50x [duplicate]

My code always outputs "No Match", so I ran it on debug50. My counting function is right some of the time, but even when I know that it's counted STRs correctly, it output's "No Match". I ran debug50 on just the code that looks for a match, and I found out that for some reason, it skips the for loops that have all the code that saves and compares everything in them. I know that the for loop runs if it's not "for i in csv_file" but instead using the range() function. I don't know why this is as I do the exact same thing earlier in my code. Csv_file is the .reader() of small.csv or large.csv, depending on what you put as the command-line-argument.

# comparing repetitions with people
csv_dic = []
count = 0
match = False
for i in csv_file:
    csv_dic.append(csv_file[i])
for line in csv_file:
    name = line[0]
    for i in range(len(maxes)):
        if csv_dic[i] == maxes[i]:
            match = True
            match_name = name
if match == True:
    print(match_name)
else:
    print("No Match")
file.close()
f.close()
like image 625
mkg15 Avatar asked Dec 22 '25 01:12

mkg15


1 Answers

I know what's your problem. When you're doing this loop:

for i in range(len(maxes)):
        if csv_dic[i] == maxes[i]:
            match = True
            match_name = name

You're not considering that csv_dict does not contain a value, but rather a name or the name of the STR itself. You should change it to this:

for i in range(1, len(maxes)):
        if csv_dic[i] == maxes[i]:
            match = True
            match_name = name

Hopes this solves your problem! :)

like image 173
Nicolas F Avatar answered Dec 23 '25 13:12

Nicolas F



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!