#You may modify the lines of code above, but don't move them! #When you Submit your code, we'll change these lines to #assign different values to the variables. #There's an easy way to do this exercise, and a hard way. For #a hint on the easier way, revisit the sample answers for the #previous coding exercise. # #Above we've created a variable called mystery_string. Write #some code that will print the first letter of the string on #the first line, the first two letters on the second line, #the first three letters on the third line, etc., until it #prints the entire string on the last line. #

Respuesta :

Answer:

The solution code is written in Python:

  1. mystery_string = "Programming"
  2. output = ""
  3. for x in mystery_string:
  4.    output += x  
  5.    print(output)

Explanation:

Firstly, create a variable mystery_string to hold a random string (Line 1).

Create an output variable to hold an output string (Line 2).

Create a for-loop to traverse the mystery_string character by character (Line 4). In the iteration, get a character from the mystery_string, and concatenate it with output string (Line 5). Print the output string (Line 6) before proceed to the next iteration.

Following are the python program to the given question:

Program Explanation:

  • Defining a variable "mystery_string" that initializes with the string value "Lucy".
  • In the next step, a for loop is declared, which uses the range and len method to calculate the string value.
  • Inside the loop, a print method is used that uses the slicing in the string variable and prints its value.

Program:

mystery_string = "Lucy"#defining a variable mystery_string that initializes with the string value

for i in range(len(mystery_string)):#defining a for loop that string value in parameter  

   print(mystery_string[:i+1])#defining a Print method that uses the slicing in the string variable and Prints its value

Output:

Please find the attached file.

Learn more:

brainly.com/question/17069825

Ver imagen codiepienagoya
Ver imagen codiepienagoya