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

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'
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%...
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!!!!!
would you tell me some list of topic that is not mathematics but can be discussed...
would you tell me some list of topic that is not mathematics but can be discussed how mathematics can be used to understand? something like egnima or turing machine, the golden ratio
PLEASE FILL IN BLANK WITH CORRECT ANSWER. THANK YOU! CHAPTER 16: ANALYSIS OF VARIANCE (ONE WAY-Factor)...
PLEASE FILL IN BLANK WITH CORRECT ANSWER. THANK YOU! CHAPTER 16: ANALYSIS OF VARIANCE (ONE WAY-Factor) Key Terms Analysis of variance (ANOVA) – An overall test of the null hypothesis fro more than two population means. One-way ANOVA – The simplest type of analysis of variance that tests whether differences exist among population means categorized by only one factor or independent variable. Treatment effect – The existence of at least one difference between the population means categorized by the independent...
I am writing a research report on nanocellulose electronics. Can you tell me what would be...
I am writing a research report on nanocellulose electronics. Can you tell me what would be considered social negatives of this development?
1. can you please use your own words to tell me what is the difference between...
1. can you please use your own words to tell me what is the difference between capital budgeting screening decisions and capital budgeting preference decisions? 2. use your own words to tell me what is meant by the term 'time value of money". 3. What is net present value (NPV)? Can it ever be negative? Explain in your own words. 4. How is the project profitability index computed, and what does it measure?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT