Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

#4) store a persons name, and include some whitespace characters at the…

Question

#4) store a persons name, and include some whitespace characters at the beginning and end of the name. make sure you use each character combination, \\\t\ and \\
\, at lease once. print the name once, so the whitespace around the name is displayed. then print the name using each of the three stripping functions, lstrip(), rstrip(), and strip(). (this means 3 additional times printing out the name, 4 total).

Explanation:

Step1: Store the name with whitespace

name = "
\t John Doe \t
"
print(name)

Step2: Use lstrip() function

print(name.lstrip())

Step3: Use rstrip() function

print(name.rstrip())

Step4: Use strip() function

print(name.strip())

Answer:

The code above first stores a name "John Doe" with whitespace characters (
and \t) at the beginning and end. Then it prints the name as - is, and then prints the name after applying lstrip(), rstrip() and strip() functions respectively. The actual output will be:

\t John Doe \t
(original with whitespace)
John Doe \t
(after lstrip())

\t John Doe (after rstrip())
John Doe (after strip())