9. Assume the string old string contains at least 4 characters. A code segment is intended to remove the first two characters and the last two characters from old string and assign the result to new string. Which of the following does NOT work as intended? (a) new_string = old_string[2:-2] (b) temp1 = old_string[2:] new_string = temp1[:len(temp1)-2] (c) new_string = old_string[2:len(old_string)] new_string = new_string[0:len(new_string)-2] (d) new_string = old_string[0:len(old_string)-2] new_string = new_string[2:len(new_string)-2]

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 8PE: Write a program that reads in a line consisting of a students name, Social Security number, user ID,...
icon
Related questions
Question
9. Assume the string old string contains at least 4 characters. A code segment is intended to remove the first two
characters and the last two characters from old string and assign the result to new string. Which of the following
does NOT work as intended?
(a) new_string = old_string[2:-2]
(b) temp1 = old_string[2:]
new_string = temp1[:len(temp1)-2]
%3D
(c) new_string = old_string[2:len(old_string)]
new_string = new_string[0:len(new_string)-2]
(d) new_string = old_string[0:len(old_string)-2]
new_string = new_string[2:len(new_string)-2]
Transcribed Image Text:9. Assume the string old string contains at least 4 characters. A code segment is intended to remove the first two characters and the last two characters from old string and assign the result to new string. Which of the following does NOT work as intended? (a) new_string = old_string[2:-2] (b) temp1 = old_string[2:] new_string = temp1[:len(temp1)-2] %3D (c) new_string = old_string[2:len(old_string)] new_string = new_string[0:len(new_string)-2] (d) new_string = old_string[0:len(old_string)-2] new_string = new_string[2:len(new_string)-2]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Character class and its methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning