Question

In: Computer Science

Can you please tell me, what would be the correct way of doing it? def updateRepresentation(blank,...

Can you please tell me, what would be the correct way of doing it?


def updateRepresentation(blank, secret, letter):
"""
This function replaces the appropriate underscores with the guessed
letter.
Eg. letter = 't', secret = "tiger", blank = "_i_er" --> returns "ti_er"
Paramters: blank, secret are strings
letter is a string, but a single letter.
Returns: a string
"""

#TODO -- complete this function so that it produces a new string
#from blank with letter inserted into the appropriate locations.
#For example:
# letter = 't', secret = "tiger", blank = "_i_er" --> newString "ti_er"
#newString should be returned.
#hint:
#iterate through each character of secret by index position
# check to see if letter = current character at index position
# if yes, add this letter to newString
# if no, add the letter from blank found at index position

#leave this line (and use the variable newString in your code
newString = ""

for i in range(len(secret)):
if letter == secret[i]:
newString= newString + letter
else:
blank= blank[:i] + letter
return newString

Solutions

Expert Solution

CODE:

OUTPUT:

Raw_code:

#function defintion of updatedRepresentation with parameters(blank,secret,letter)
def updateRepresentation(blank,secret,letter):
#declaring a newString
newString=""
#for loop is iterating with range of length of the secret message
for i in range(len(secret)):
#if the letter is found in secret message store the index value
if(letter==secret[i]):
index=i
#replacing the letter with blank(_) in the appropriate index
blank=blank[:index]+letter+blank[index+1:]
#copying the blank string in newString
newString=blank
#returning the newString
return newString
#entering a single letter
letter=input("Enter a single letter:")
#entering a secret message
secret=input("Enter a secret message:")
#enter a blank message that means entering the secret message with some blanks(_) in the replace of some characters
blank=input("Enter the blank message which should be like secret with some blank spaces(use underscore for blanks):")
#calling the updateRepresentation with parameters of(blank,secret,letter) and storing the returned string in blank
blank=updateRepresentation(blank,secret,letter)
#printing the updated blank string
print("The updated string is:",blank)

************For any queries comment me in the comment box **************


Related Solutions

You are Head of HR for your company. Tell me what you would be doing to...
You are Head of HR for your company. Tell me what you would be doing to work with the staff and overall organization in this current COVID-19 crisis? Consider everything we have discussed up to this point around performance, measurements, talent management, compensation, and overall strategic objectives
Before doing this please tell me what is lift factor and tell me how did we...
Before doing this please tell me what is lift factor and tell me how did we calculate seasonal index for carlson's sales of january as 0.957 The Carlson Department store suffered heavy damage when a hurricane struck on August 31. The store was closed for four months (September through December), and Carlson is now involved in a dispute with its insurance company about the amount of lost sales during the time the store was closed. Two key issues must be...
Can you tell me what is wrong with this code ? def update_char_view(phrase: str, current_view: str,...
Can you tell me what is wrong with this code ? def update_char_view(phrase: str, current_view: str, index: int, guess: str)->str: if guess in phrase: current_view = current_view.replace(current_view[index], guess) else: current_view = current_view    return current_view update_char_view("animal", "a^imal" , 1, "n") 'animal' update_char_view("animal", "a^m^l", 3, "a") 'aamal'
I was wondering if you can tell me if the following code is correct and if...
I was wondering if you can tell me if the following code is correct and if its not can it be fixed so it does not have any syntax errors. Client one /** * Maintains information on an insurance client. * * @author Doyt Perry/<add your name here> * @version Fall 2019 */ public class Client { // instance variables private String lastName; private String firstName; private int age; private int height; private int weight; /** * First constructor for...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my professor said to always multiply the lipids by 3 and then divide by 7 to get the total amount of cals of lipids per day... I'm not completely sure why you do that? Can someone explain. Why don't you just stop at 700 cals for lipids? 1. Calculate the number of calories and grams protein for the following TPN solution: D50W in 500cc 10%...
Can you please tell me if this code needs to be fixed, if it does can...
Can you please tell me if this code needs to be fixed, if it does can you please post the fixed code below please and thank you /** * Models a Whole Life Policy. * * @author Tina Comston * @version Fall 2019 */ public class WholeLifePolicy { // instance variables    private double faceValue; // your code here - code the remaining instance field // constants /** * surrender rate. */ public static final double SURRENDER_RATE = .65; /**...
Can you please tell me if this code needs to be fixed, if it does can...
Can you please tell me if this code needs to be fixed, if it does can you please post the fixed code below please and thank you /** * Driver to demonstrate WholeLifePolicy class. * * @author Tina Comston * @version Fall 2019 */ public class WholeLifePolicyDriver { /** * Creates WholeLifePolicy object, calls methods, displays values. * */ public static void main() { WholeLifePolicyDriver myDriver = new WholeLifePolicyDriver(); // create a policy WholeLifePolicy policy = new WholeLifePolicy("WLP1234567", 50000, 20);...
what is the correct way of doing a anatomy lab report?
what is the correct way of doing a anatomy lab report?
please show me or tell me a trick, on how can i tell right away when...
please show me or tell me a trick, on how can i tell right away when a characteristics equation(system) is 1)overdamped 2)underdamped 3)critically damped 4) nonlinear show each an example write neatly!!!!!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT