Ask Question
13 July, 04:33

Write the code to transverse through the string "INST126" printing each character using a for loop and then using a while loop.

course = 'INST126'

then finish the code and make the output print "Welcome to INST 326!" when calling print with the argument course. Use concatenation and string slicing to change the value stored by the variable course. (Hint: Are strings mutable or immutable?)

+5
Answers (1)
  1. 13 July, 05:54
    0
    The solution code is written in Python 3

    course = 'INST126' for x in course: print (x) length = len (course) i = 0 while i < length: print (course[i]) i+=1 course = "Welcome to " + course + "!" print (course)

    Explanation:

    The code in line 2-3 and line 5-9 are to use for-loop and while loop to print the course string character by character. This is possible to use the loop to traverse through the string and extract each character and print them out.

    We can concatenate the string as shown in Line 11 and print a joined string (Line 12). But we can't slice the string and change the individual character as strings are immutable.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write the code to transverse through the string "INST126" printing each character using a for loop and then using a while loop. course = ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers