{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Programming with Python\n",
"#### Stefan Güttel, [guettel.com](http://guettel.com)\n",
"\n",
"## Test 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Problem 1.** Write a program that loads an integer `n` and a natural number `k`. The program has to verify that `k > 0` and, if it is so, print the `k`-th digit of `n` from the right; if `k <= 0`, a descriptive error must be reported with no further computation nor outputs.\n",
"\n",
"If `n` has less than `k` digits, the program should print `0` (a zero).\n",
"\n",
"For example, for $n = 1234567$ and $k = 3$, the program has to print the digit $5$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Problem 2.** One generalization of Fibonacci numbers is defined as follows:\n",
"$$F_0 = 0, \\quad F_1 = 1, \\quad F_{k+2} = pF_{k+1} + F_{k}, \\quad k \\in \\mathbb{N}_0, \\quad p \\in \\mathbb{R}.$$\n",
"Write a program that loads $p \\in \\mathbb{R}$ and two natural numbers $a$ and $b$. The program has to print all numbers $F_k$ for $k$ between $a$ and $b$, including the two of them.\n",
"\n",
"**Note:** The program has to work properly regardless of the order of $a$ and $b$, i.e.,\n",
"* when $a < b$ it should print $F_a, F_{a+1}, \\dots, F_b$,\n",
"* when $a = b$ it should print $F_a$,\n",
"* when $a > b$ it should print $F_b, F_{b+1}, \\dots, F_a$.\n",
"\n",
"Swapping `a` and `b` is allowed."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}