Basic (2) P25788


Statement
 

pdf   zip

You have to program several functions. In each case, few lines of code are enough.

  1. Write a function @vowel_consonant(s)@ that given an string ss returns the number of vowels and consonants that appear as characters in ss. We assume all characters of ss are letters.

  2. Write a function @delete_digits(s)@ that returns the string obtained after ruling out the digit characters of ss.

  3. Write a function @switch(s)@ that given an string ss returns the string obtained after switching lowercase to uppercase letters and the other way around. Non letter characters do not change. Warning: do not use the @swapcase@ string method.

  4. Write a function @countdown(n)@ that given an integer nn greater than zero prints the count down until 00.

  5. Write a function @powers_of_2(n)@ that given a natural nn prints the nn first powers of 2.

Scoring

Every function counts 20 points.

Sample session

Sample session
>>> vowel_consonant("SpartacUs")
(3, 6)
>>> delete_digits("#Pelham 1-2-3#")
#Pelham --#
>>> switch("#Pelham 1-2-3#")
#pELHAM 1-2-3#
>>> countdown(7)
7 6 5 4 3 2 1 0
>>> powers_of_2(6)
1 2 4 8 16 32
Information
Author
Jorge Castro
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python