Ask Question

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?)

+4
Answers (1)
  1. 21 February, 11:24
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers