These questions follow Working with Text. Text typed by a person is never as tidy as text typed by you, and every question here is a small version of a bug that has genuinely broken somebody’s program.

Reading text

  1. With title = "Fifteen Dogs", what does each print? len(title), title[0], title[-1], title[0:7].
  2. Why is " Priya " == "Priya" False, and what one method call fixes it?
  3. What do each of these produce: "14".isdigit(), "3.5".isdigit(), " 14".isdigit(), "".isdigit()? What does .isdigit() actually test?
  4. Find the fault.
    name = "priya"
    name[0] = "P"

Working with text

  1. A saved line looks like Fifteen Dogs|14. Split it into the title and the number of days, and print the number of days plus one.
  2. A sign-in check should accept PRIYA, priya, and Priya . Write the condition.
  3. Given full = "Priya Nair", print the initials PN.
  4. Challenge. Count the vowels in "Fifteen Dogs", ignoring case.

Answers