Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1: Given the initial statements: s1 = \"spam\" and s2 = \"ni!\" Show the

ID: 3832334 • Letter: P

Question

Problem 1:

Given the initial statements: s1 = "spam" and s2 = "ni!"

Show the result of evaluating each of the following string expressions:

a) "The Knights who say, " + s2

b) 3 * s1 + 2 * s2

c) s1[1]

d) s1[1:3]

e) s1[2] + s2[ :2]

f) s1 + s2[-1]

g) s1.upper()

h) s2.upper().ljust(4) * 3

Problem 2:

Given the same initial statements as in the previous problem, show a Python expression that could construct each of the following results by performing string operations on s1 and s2.

a) "NI"

b) "ni!spamni!"

c) "Spam Ni! Spam Ni! Spam Ni!"

d) "spam"

e) ["sp", "m"]

f) "spm"

Explanation / Answer

a) "The Knights who say, " + s2 --------- The Knights who say, ni!

b) 3 * s1 + 2 * s2 -----------   spamspamspamni!ni!

c) s1[1] ----------- p (it will print the char at index 1)

d) s1[1:3] ---------- pa (it will print the characters from index 1 to2)

e) s1[2] + s2[ :2] ------- ani

f) s1 + s2[-1] ----- spam!

g) s1.upper() ----- SPAM

h) s2.upper().ljust(4) * 3


2)

a) "NI" ------------ s2.upper()

b) "ni!spamni!" ---------- s2+s1+s2

c) "Spam Ni! Spam Ni! Spam Ni!" ------ 3* (s1[0].upper() + s1[1:4]+" "+s2[0].upper()+s2[1:3])

d) "spam" ----------- s1

due to time constraint i am not able to answer all the questions