Simple types and strings (1) X26735


Statement
 

pdf   zip

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

  1. Write a function @drawH(n)@ that given an odd integer n3n\ge 3 prints a letter H of size nn formed with symbol . Follow the pattern of the example below.

  2. Write a function @area_circle(r)@ that given a float number r0r\ge 0 returns, rounded to the hundredth, the area of the circle of radius rr. Use the pi constant defined in the math module.

  3. Write a function @slow_pi_aprox(n)@ that given a non negative integer nn computes 4k=0n(1)k2k+14\sum_{k = 0}^n \frac{(-1)^k}{2k + 1} rounded to the hundredth.

  4. Write a function @is_univariate_number(n)@ that given a non negative integer returns a boolean pointing out whether nn is represented using only one digit. For instance 2222222222 is univariate but 2232222322 is not.

  5. Write a boolean function @is_univariate_word(s)@ that given an string ss returns True if and only if ss is formed using only one letter. For instance word xxXxXXx is univariate but xxXxy is not. We assume ss is non empty and all characters of ss are letters.

Scoring

Every function counts 20 points.

Sample session

Sample session
>>> drawH(5)
*   *
*   *
*****
*   *
*   *
>>> area_circle(2.5)
19.63
>>> slow_pi_aprox(50)
3.16
>>> is_univariate_number(22322)
False
>>> is_univariate_word("xxXxXXx")
True
Information
Author
Jorge Castro
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python