Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## I had issues understanding problem 4
- #1 Print every character in the string "Camus".
- def printletters():
- frststrng = "Camus"
- for letter in frststrng:
- print(letter)
- printletters()
- #2 Write a program that collects two strings from a user,
- # inserts them into the string "Yesterday I wrote a [response_one]. I sent it to [response_ two]!" and prints a new string.
- def addastring():
- firststring = input(" Enter a word ")
- secondstring = input(" Enter a word ")
- print("Yesterday I wrote {}. I sent it to {}!".format(firststring,secondstring))
- addastring()
- # 3 Use a method to make the string "aldous Huxley was born in 1894." grammatically correct by capitalizing the first letter in the sentence.
- ### Why does .capitalize() take off the second capital letter?
- thirdstring = "aldous Huxley was born in 1894.".capitalize()
- print(thirdstring)
- def oddcharacterscapital(string,index):
- print(string[:index].capitalize() + string[index:].capitalize())
- comparestring = "aldous Huxley was born in 1894."
- oddcharacterscapital(comparestring,7)
- #4 Take the string "Where now? Who now? When now?" and call a method that returns a list that looks like: ["Where now?", "Who now?", "When now?"].
- #having trouble splitting the string correctly
- fourthstring = """Where now? Who now? When now?"""
- print(fourthstring.split(" "))
- ##5 Replace every instance of "s" in "A screaming comes across the sky." with a dollar sign.
- fifthstring = "A screaming comes across the sky."
- print(fifthstring.replace("s","$",5))
- ##6 Use a method to find the first index of the character "m" in the string "Hemingway".
- sixthstring = "Hemingway"
- print(sixthstring.find("m"))
- #7 Create the string "three three three" using concatenation, and then again using multiplication
- seventhstring = "three"
- print(seventhstring+seventhstring+seventhstring)
- print(seventhstring*3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement