You are tasked with helping write part of an exciting new word-guessing game, “Durdle”. The game is one in which a player attempts to guess a five-letter word in successive guesses. In this problem and the next one, we will build an implementation of this word-guessing game. First, to support this game, we will write a function named durdle_match(guess, target) that takes in two strings - a player’s guess, and the target word that the player is attempting to guess. Each of the given words is five letters long. This function should return a five-letter string consisting of the letters B, G, and Y that has a meaning associated with the guess as follows: B: This letter in the guess does not appear in the target string Y: This letter in the guess appears in the target string in another location G: This letter in the guess appears in the same location in the target string
You are tasked with helping write part of an exciting new word-guessing game, “Durdle”. The game is one in which a player attempts to guess a five-letter word in successive guesses. In this problem and the next one, we will build an implementation of this word-guessing game. First, to support this game, we will write a function named durdle_match(guess, target) that takes in two strings - a player’s guess, and the target word that the player is attempting to guess. Each of the given words is five letters long. This function should return a five-letter string consisting of the letters B, G, and Y that has a meaning associated with the guess as follows:
- B: This letter in the guess does not appear in the target string
- Y: This letter in the guess appears in the target string in another location
- G: This letter in the guess appears in the same location in the target string
Python Code:
def durdle_match(a, b):
word=""
for i in range(5):
if(a[i]==b[i]):
word=word+"G"
elif(a[i] in b):
word=word+"Y"
else:
word=word+"B"
return(word)
target="perky"
guess="threw"
print(durdle_match(guess,target))
Trending now
This is a popular solution!
Step by step
Solved in 2 steps