def seq_numbers(string): count=3 #Create a function Constants that will check if
ID: 3919109 • Letter: D
Question
def seq_numbers(string):
count=3
#Create a function Constants that will check if the string/ password
#has no sequence of 3 or more numbers. If the string has does not, then return a score of +3'''
n = len(string) # the length of the string
string = string +".." # to make up for the checking of the last two characters
for i in range(0,n):
if(string[i] >= '0' and string[i] <= '9'): #checking if the first character is a number
if(string[i+1] >= '0' and string[i+1] <= '9'): #checking if the second character is a number
if(string[i+2] >= '0' and string[i+2] <= '9'): #checking if the thrid character is a number
score = 0 # if three consecutive numbers which is the minimmum condition, return nothing
return count # else return 3
what does string = string +".." mean in this context and is this a better way to write this code more concise and optimize. If so explain why the new code is better
Explanation / Answer
Answer: -------- As said in the comments it is used to make up for the checking of the last two characters It is a bit cleaner and efficient to use range(0, n-2) instead of using the above trick. Revised code: ---------------- def seq_numbers(string): count = 3 # Create a function Constants that will check if the string/ password # has no sequence of 3 or more numbers. If the string has does not, then return a score of +3''' n = len(string) # the length of the string string = string + ".." # to make up for the checking of the last two characters for i in range(0, n-2): if (string[i] >= '0' and string[i] = '0' and string[i + 1] = '0' and string[i + 2]Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.