Last active
August 29, 2015 14:15
-
-
Save cwake/468cf38f5f32c0e1806b to your computer and use it in GitHub Desktop.
Week 5 Practice Exercises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1 = "spam" | |
s2 = "ni!" | |
#test these | |
print("The Knights who say, " + s2) # The Knights who say, ni! | |
print(3 * s1 + 2 * s2) # spamspamspamni!ni! | |
print(s1[1]) # p | |
print(s1[1:3]) # pa | |
print(s1[2] + s2[:2]) # ani | |
print(s1 + s2[-1]) # spam! | |
print(s1.upper()) # SPAM | |
print(s2.upper().ljust(4) * 3) # NI! NI! NI! | |
# test the reverse constructions | |
print(s2[:2].upper()) # NI | |
print(s2 + s1 + s2) # ni!spamni! | |
print((s1.capitalize().ljust(5) + s2.capitalize().ljust(4)) * 3) # Spam Ni! Spam Ni! Spam Ni! | |
print(s1) # spam | |
print("[\"" + s1[:2] + "\", \"" + s1[3] + "\"]") # ["sp", "m"] if you wanted it verbatim what the book has (confusing notation) | |
print(s1[:2] + "\n" + s1[3]) # if you meant you wanted it on two separate lines (confusing notation) | |
print(s1[:2] + s1[-1]) # spm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment