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.
-
csp-9-3-1: Change the mirroring program to mirror the phrase
- Make the phrase
"Time to panic!"
- That would give us
!cinaP ot emiTTime to Panic!
. - Change the
new_string
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 + "!" + new_string + 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 + new_string + "!" + 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.
"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.
-
csp-9-3-2: When the variable
- 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
new_string
.
letter
contains the "W"
from Wizard
, how many exclamation points are in new_string
?
csp-9-3-4: csp-9-3-3: The phrase "A but tuba"
is a palindrome. The letters are the same forward and backward. The below program generates the output: "abut tub a<=>a but tuba"
Put the lines in the right order with the right indentation.
new_str = "<=>"
phrase = "a but tuba"
---
for char in phrase:
---
new_str = char + new_str + char
---
print(new_str)