Posts: 544
Threads: 15
Joined: Oct 2016
1. Next time. Show the work. That you want help on.
It pretty simple.
Just loop over word.
Compare against correct word code.
Try it yourself then look at code.
def loop_match(command, code):
errors = 0
i = 0
for letter in command:
while letter != code[i]:
errors += 1
i += 1
if i >= len(code):
break
i += 1
if i >= len(code):
break
return errors
def straight_match(command, code):
errors = 0
for i in range(min(len(code), len(command))):
if command[i] != code[i]:
errors += 1
return errors + abs(len(code) - len(command))
def match(command, code):
return min( loop_match(command, code),
straight_match(command, code) )
code = 'sddddwx'
print(match('sddwx', code))
print(match('sddddx', code))
print(match('sdddwwx', code))
print(match(code, code))
99 percent of computer problems exists between chair and keyboard.