Kira-Kun
asked on
Python: Find Character Exist, but not in correct position
Hello all, I am trying to achieve something like this:
Say the magic word is "aabb"
The user suppose to guess it, however if the user for example typed "abab", it should tell them that one of the "a" is in the right position, while the other is not. How should I go about doing that?
Thanks!
*This is quite urgent, so if someone can reply really fast, that would be great! Thanks!
Say the magic word is "aabb"
The user suppose to guess it, however if the user for example typed "abab", it should tell them that one of the "a" is in the right position, while the other is not. How should I go about doing that?
Thanks!
*This is quite urgent, so if someone can reply really fast, that would be great! Thanks!
well, first learn python : http://docs.python.org/tutorial/
then for your project, choose the right tools on strings : http://docs.python.org/library/strings.html
and input output (which you'll have learned in the tutorial)
and on random's usage : http://docs.python.org/library/random.html
so you can generate the aabb or abab or whatever...
now you have all the RTFM you need to start, and we're here to help you if you have *real* questions about python. We're not here to do your homework, but to help you get more knowledge, so I'm following pepr's comment.
then for your project, choose the right tools on strings : http://docs.python.org/library/strings.html
and input output (which you'll have learned in the tutorial)
and on random's usage : http://docs.python.org/library/random.html
so you can generate the aabb or abab or whatever...
now you have all the RTFM you need to start, and we're here to help you if you have *real* questions about python. We're not here to do your homework, but to help you get more knowledge, so I'm following pepr's comment.
Would this be enough?
word = "aabb"
guess = "abab"
if not len(word) == len(guess):
print "error"
for i in range(len(word)):
if word[i] == guess[i]:
print "The letter %s on position %d is correct" % (guess[i], i)
else:
print "The letter %s on position %d is not correct" % (guess[i], i)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is it a kind of the implementation of the Master Mind game?