vendredi 29 septembre 2017

Can multiple if statements be used in a for loop?

Is there a way to make a for loop iterate a list of strings by using some multiple conditions?. I am trying to build a for loop which should iterate each element of a list made of strings, but it looks like my for loop doesn't operate each condition to each iterable of my list.

For instance,

I have many strings which differs due to their own contents, E.g(DNA has 'T' instead of 'U', RNA has 'U' instead of 'T' and an unknow (UNK) which has neither 'T' nor 'U' or any other characters.

The input is ['tacaactgatcatt', 'aagggcagccugggau','gaaaaggcaggcg','guaccaguuu'.'acggggaccgac'] The output should be the type of DNA sequence:

Result: DNA, RNA, UNK, RNA, UNK

I think my mistake is due to a misuse of break sentences in a for loop, but I can't figure out how to fix it.

This is what I get so far:

seq = list(input('Enter your sequence:').upper())

for obj in seq:
    if 'U' not in obj and 'T' in obj:
        print('Result: DNA')
        break


    if 'U' in obj and 'T' not in obj:
       print('Result: RNA')
       break


else:
    print('Result: UNK')

Aucun commentaire:

Enregistrer un commentaire