Skip to content
Snippets Groups Projects
Commit df50fff4 authored by s2032074's avatar s2032074
Browse files

the length of the correct sequence is calculated

parent 56078b1e
No related branches found
No related tags found
Loading
......@@ -173,17 +173,39 @@ class Sequence:
k=-1
#we can compare sequences only if they are of the same length
if len(user_seq) != len(self.sequence):
if len(user_seq) == len(self.sequence):
k = 0
#the loop comparing two sequences by comparing each pair of elements
for i in range(len(self.sequence)):
#if elements on the same position in two sequences are not equal,
#then the counter is getting +1
if user_seq[i].ID == self.sequence[i].ID:
if user_seq[i].ID != self.sequence[i].ID:
k = k + 1
return k
# user_seq -- the sequence which user entered
def compare_sequences_length(self, user_seq):
'''this method compares sequences and returns the length of the correctly repeated sequence'''
#k -- counter for errors that user made while repeating the pattern
#if this metod returns -1, we know that there is an error in input
k=-1
#we can compare sequences only if they are of the same length
if len(user_seq) == len(self.sequence):
k = 0
#the loop comparing two sequences by comparing each pair of elements
for i in range(len(self.sequence)):
#if elements on the same position in two sequences are not equal,
#then then break
if user_seq[i].ID != self.sequence[i].ID:
break
#if elements on the same position are equal, the length of the correct
#sequence is increased by 1
k = k + 1
return k
#this class will be tested, thus, we need this main method
#as it sets the environment where we are going to test
def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment