Simple types and strings (2) X26700


Statement
 

pdf   zip

html

You have to program several functions. In each case, few lines of code are enough. Warning: do not use the split string method.

  1. Write a function um_count(s) that given an string s returns the number of times character u is followed by character m in string s.
  2. Write an integer function word_count(s) that returns the number of words in string s. We assume all characters of s are letters and spaces.
  3. Write a function kth_word(s, k) that given a string s and an integer k≥ 1 returns the kth word in string s. If s has less than k words it returns the empty string. We assume all characters of s are letters and spaces.
  4. Write a function suc_word(s) that given a string s and returns the first word in string s that has some uppercase letter. If all the letters in s are lowercase it returns the empty string. We assume all characters of s are letters and spaces.
  5. Write a function drawA(n) that given an odd integer n≥ 3 prints a letter A of size n formed with symbol *.

Scoring

Every function counts 20 points.

Sample session
>>> um_count("Qui invenit amicum invenit thesauruM")
1
>>> word_count("Alea iacta          est")
3
>>> kth_word("Alea iacta est", 3)
est
>>> suc_word("qui invenit amiCum invenit thesauruM")
amiCum
>>> drawA(5)
    *
   * *
  *****
 *     *
*       *
Information
Author
Jorge Castro
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python