Mirroring Text¶
What happens if we add the letter to both sides of the new string that we’re making?
Try changing the phrase and see what effects you can generate.
- Make the phrase
"Time to panic!"
- That would give us
!cinaP ot emiTTime to Panic!
. - Change the
newString
in line 1 to"!"
instead of"" - We can start our accumulator with something in it.
- Change the right hand side of line 4 to
letter + "!" + newstring + letter
- That would give us
!!c!i!n!a!P! !o!t! !e!m!i!T!Time to Panic!
-- exclamation points between the letters in the first half of the mirror. - Change the right hand side of line 4 to
letter + newstring + "!" + letter
- That would give us
!cinaP ot emiT!T!i!m!e! !t!o! !P!a!n!i!c!!
-- exclamation points between the letters in the second half of the mirror.
csp-9-3-2: Change the mirroring program to mirror the phrase "Time to Panic"
with a single exclamation point in the middle, to make the printed words look like this: cinaP ot emiT!Time to Panic
. How do you do it?
The accumulator doesn’t have to be set to be an empty string. You can put something in the accumulator, and then it will show up in the middle of the mirrored phrase.
- One
- There is just the one in the accumulator to start.
- Two
- If we just mirrored the string, there would be only two. But we are mirroring with something in the accumulator.
- Three
- That is true at the end, but not when letter contains the first letter of
"Wizard"
- Four
- At most, there will be three in
newString
.
csp-9-3-4: When the variable letter
contains the "W"
from Wizard
, how many exclamation points are in newString
?
<p>The phrase <code>”A but tuba”</code> is a <b>palindrome</b>. The letters are the same forward and backward. The below program generates the output: <code>”abut tub a<=>a but tuba”</code> Put the lines in the right order with the right indentation.</p>