Write code that inserts userItems into the output string stream itemsOSS until the user enters "Exit". Each item should be followed by a space. Sample output if user input is "red purple yellow Exit": red purple yellow

Respuesta :

Answer:

The solution code is written in Python:

  1. itemsOSS = ""
  2. userItem = input("Enter an item: ")
  3. while(item != "Exit"):
  4.    itemsOSS += userItem + " "
  5.    userItem = input("Enter an item: ")
  6. print(itemsOSS)

Explanation:

Firstly, we create a variable itemsOSS (intialized it with empty string) and use it as output string stream (Line 1).

Next use input function to prompt user to enter first item (Line 2)

While the item value is not "Exit" (Line 4), append userItem to variable itemsOSS.

When the user enter "Exit", use print function to print the itemsOSS string (Line 8).

Q&A Education