How to write the body function using for loop def is dnapali

How to write the body function using for loop? def is _dna_palindrome(x, y): \" \" \" (str, str) bool Both parameters are strings representing DNA strands. The two strands form DNA: is_dna would return True if called on the two inputs. Return True if and only if the DNA strands represented by the two parameters form a DNA palindrome. >>> is_dna_palindrome(\"GGCC\", \"CCGG\") True >>> is_dna_paindrome(\"CCCGGG\", \"AGCT\") False >>> is_dna_palindrome(\"GACGC\", \"CGCAG\")True \" \" \"

Solution

def is_dna_palindrome(x,y):
l1 = len(x)
l2 = len(y)
if l1 == l2:
for i in range (0,l1):
if x[i] != y[l1-1-i]:
return False;
else:
return True;
else:
return False;

  
print is_dna_palindrome(\"GGCC\", \"CCGG\")
print is_dna_palindrome(\"CCCGGG\", \"AGCT\")

print is_dna_palindrome(\"GACGC\", \"CGCAG\")

Output:

sh-4.3$ python main.py

sh-4.3$ python main.py

True                                                                                                                                                                                                                        

False                                                                                                                                                                                                                       

True   

 How to write the body function using for loop? def is _dna_palindrome(x, y): \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site