Python — Functions with numbers

In this problem you must implement several functions in Python.

  1. Write a function @absValue(x)@ that, given a number, returns its absolute value.

  2. Write a function @power(x, p)@ that, given a number xx and a natural pp, returns xx raised to pp, that is, xpx^p.

  3. Write a function @isPrime(x)@ that, given a natural, returns a Boolean that tells whether it is a prime number or not.

  4. Write a function @slowFib(n)@ that, returns the nn-th element of the Fibonacci sequence using the recursive algorithm according to its definition (f(0)=0f(0)=0, f(1)=1f(1)=1, f(n)=f(n1)+f(n2)f(n)=f(n-1)+f(n-2) for n2n\ge 2).

  5. Write a function @quickFib(n)@ that, returns the nn-th element of the Fibonacci sequence using a faster algorithm.

Scoring

Each function scores 20 points.

Sample session

Problem information

Author: Unknown
Translator: Jordi Petit

Generation: 2026-01-25T12:03:11.125Z

© Jutge.org, 2006–2026.
https://jutge.org