SHARE
TWEET

Untitled

a guest Oct 21st, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## I had issues understanding problem 4
  2.  
  3. #1 Print every character in the string "Camus".
  4. def printletters():
  5.     frststrng = "Camus"
  6.     for letter in frststrng:
  7.         print(letter)
  8. printletters()
  9.  
  10. #2 Write a program that collects two strings from a user,
  11. #  inserts them into the string "Yesterday I wrote a [response_one]. I sent it to [response_ two]!" and prints a new string.
  12.  
  13. def addastring():
  14.     firststring = input(" Enter a word  ")
  15.     secondstring = input(" Enter a word  ")
  16.     print("Yesterday I wrote {}. I sent it to {}!".format(firststring,secondstring))
  17. addastring()
  18.  
  19. # 3 Use a method to make the string "aldous Huxley was born in 1894." grammatically correct by capitalizing the first letter in the sentence.
  20. ### Why does .capitalize() take off the second capital letter?
  21.  
  22. thirdstring = "aldous Huxley was born in 1894.".capitalize()
  23. print(thirdstring)
  24.  
  25. def oddcharacterscapital(string,index):
  26.     print(string[:index].capitalize() + string[index:].capitalize())
  27.  
  28. comparestring = "aldous Huxley was born in 1894."
  29. oddcharacterscapital(comparestring,7)
  30.  
  31.  
  32. #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?"].
  33. #having trouble splitting the string correctly
  34. fourthstring = """Where now? Who now? When now?"""
  35. print(fourthstring.split("  "))
  36.  
  37. ##5 Replace every instance of "s" in "A screaming comes across the sky." with a dollar sign.
  38. fifthstring = "A screaming comes across the sky."
  39. print(fifthstring.replace("s","$",5))
  40.  
  41. ##6 Use a method to find the first index of the character "m" in the string "Hemingway".
  42. sixthstring = "Hemingway"
  43. print(sixthstring.find("m"))
  44.  
  45.  
  46. #7 Create the string "three three three" using concatenation, and then again using multiplication
  47. seventhstring = "three"
  48. print(seventhstring+seventhstring+seventhstring)
  49. print(seventhstring*3)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top