samedi 23 septembre 2017

How to fix this multiple if statement? [duplicate]

This question already has an answer here:

I have created a multiple If statement and counters in order to count some letter from a string given by the user. But I dont know why actually this if statement doesnt differ between the first condition and the following ones.

For instance, in the following string I should be given the following output:

Enter DNA sequence:aaAAttccCggGnnxXyUU
Your sequence contain: 24 bases with the following structure:
adenine= 24
thymine= 0
cytosine= 0
guanine= 0
no_DNA_bases= 0 Please check your sequence

it should be:
adenine =  4
thymine = 2 
cytosine = 3
guanine = 3
no_DNA_bases= 12 Please check your sequence

This is my code:

sequence = str(input('Enter DNA sequence:'))
adenine = 0
thymine = 0
cytosine = 0
guanine = 0
no_DNA_bases = 0
for i in sequence:
    if i == ('A') or ('a'):
        adenine += 1
    elif i == ('T') or ('t'):
        thymine += 1
    elif i == ('C') or ('c'):
        cytosine += 1
    elif i == ('G') or ('g'):
        guanine += 1
    else:
        no_DNA_bases += 1


print('Your sequence contain:',len(sequence), 'bases', 'with the following 
structure:')

print('adenine=', adenine)
print('thymine=', thymine)
print('cytosine=', cytosine)
print('guanine=', guanine)
print('no_DNA_bases=', no_DNA_bases, 'Please check your sequence')

Aucun commentaire:

Enregistrer un commentaire