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.
Posts: 544
Threads: 15
Joined: Oct 2016
Loop over the word.
Then you compare it to your correct output.
for loop.
word = 'sdddwx'
for letter in word:
print(letter)
for range loop
word = 'sdddwx'
for i in range(len(word)):
print(word[i])
while loop
word = 'sdddwx'
length = len(word)
i = 0
while i < length:
print(word[i])
i += 1
99 percent of computer problems exists between chair and keyboard.
Posts: 544
Threads: 15
Joined: Oct 2016
Apr-06-2018, 11:38 PM
(This post was last modified: Apr-06-2018, 11:39 PM by Windspar.)
1. Seems like you need to go through the beginner tutorials. Before making a game.
basic programming.
a. variables (integer, float, strings, etc)
b. logic and logic operators (if .. elif .. else) (==, !=. etc)
c. loops (for, while)
d. functions (def)
e. containers (tuple, list, dict, class)
f. keywords
If logic.
code = 'sddddwx'
word = 'sdddwwx'
if word[0] == code[0]:
print(True)
example. Try mixing logic with a loop. Before looking at code.
code = 'sddddwx'
word = 'sdddwwx'
errors = 0
for i in range(min(len(code), len(word))):
if code[i] != word[i]:
errors += 1
print errors
99 percent of computer problems exists between chair and keyboard.
Posts: 544
Threads: 15
Joined: Oct 2016
Apr-07-2018, 02:19 PM
(This post was last modified: Apr-07-2018, 02:20 PM by Windspar.)
To solve your problem. A few keywords and a loop with logic.
keyword min
print(min(5, 3))
keyword range.
print(list(range(10))
for i in range(10):
print(i)
keyword len
word = 'sddwx'
print(len(word))
play with code.
try to solve it yourself.
then look at code in above post.
99 percent of computer problems exists between chair and keyboard.