2) c. Strings Examples




Phylyp wants to say ‘Hey, nice day!’ to Pepy but is too shy to do that in person. Maybe typing it in Python it’s easier for now! Help Phylyp type and print his first string ever.

1
2
Output:
Hey, nice day!




Phylyp changed his mind. He wants to say ‘Hey, nice day, isn’t it?’ to Pepy. Can you do that too?

1
2
Output:
Hey, nice day, isn't it?




Pepy liked Phylyp’s game! She wants to respond something playful: “Nice day it is\n’t :)”. However, when she types that inside a Python print command, it returns something slightly different. Can you verify it? What is Pepy doing wrong?

1
2
3
Output:
Nice day it is
't :)




Tyron has been eavesdropping on their conversation and wants to intervene. He wants to print “beautiful, beautiful, beautiful, beautiful, beautiful, “. But he realizes it is a ‚Ķfair amount of characters to type there! Help lazy Tyron print the above string, in a short way, with the print statement.




“Wow, that was a mouthful,” said Phylyp. “Indeed! How many characters where there?” asked Pepy. Can you help Pepy answer that in a short, clever, Pythonic way?

1
2
3
Output:
24
40




Tyron wants to tease Phylyp and Pepy. He has two variables, name1, and name2, that store their respective names. When he is asked ‘Who are you?’ Tyron replies ‘PepyPhylyp’! How can Tyron do that in Python?

1
2
3
Output:
Who are you?
Hi! I am PhylypPepy




To move on with teasing, Tyron wants to create anagrams of Pepy’s and Phylyp’s names, so that everyone is confused. Write a short Python piece of code that assigns the name Pepy to variable name1 and Phylyp variable name2. Note the different characters! (hint: use string slicing and rename the variables).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output:
Pep
epy

p
y
l
y
h
P

hyl

hylyp