{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build a function **countDown** which takes as parameter a positive number and prints a countdown down from that number to 1 and then prints Blastoff!\n",
"
Pay attention to people inserting numbers smaller than 1 or non integer numbers."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build a function showNumbers that takes a parameter called N. It should print all the numbers between 1 and N with a label to identify the even and odd numbers. \n",
"
For example, if N is 4, it should print:\n",
"
1 ODD\n",
"
2 EVEN\n",
"
3 ODD\n",
"
4 EVEN"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You probably have build a function which does N comparisons to check whether the number is even or odd. Suppose that you do not know about operator %. Rewrite the function in such a way that it produces the same output but never does any comparison to check whether a number is even or odd.\n",
"
Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
" Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
" Write function sumMultiples that takes as parameter N and returns the sum of multiples of 4 between 0 and N. For example, if N is 20, it should return 60, which is the sum of 4, 8, 12, 16, 20.\n",
" Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
" After having done it, modify the function in such a way that it works also with a generic number instead of 4. Your function should accept two parameters, N and divisor and returns the sum of multiples of divisor between 0 and N."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"DIFFICULT\n",
" Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
" Strategy: after having thought at the problem, if you can't come up with a working algorithm click below to reveal it. I said after having thought\n",
"
Write function **printTimeTable** that takes as input two positive integer numbers R and C and prints a timetable, with R rows and C columns, with \"empty\" inside each cell.\n",
"
For example, printTimeTable(5,4) should return\n",
"Hour - Day 1 - Day 2 - Day 3 - Day 4 - \n",
"h 1 - empty - empty - empty - empty - \n",
"h 2 - empty - empty - empty - empty - \n",
"h 3 - empty - empty - empty - empty - \n",
"h 4 - empty - empty - empty - empty - \n",
"h 5 - empty - empty - empty - empty - \n",
"
\n",
"
Write a function that returns the sum of multiples of X between 0 and N.\n",
"
This is how this exercise would be written in any class for to-be computer scientists :-) \n",
"
I instead write it like this\n",
"
Define a function **findDouble** which takes as parameter a string and finds the first position of two identical characters, returning -1 if there are none.\n",
"
For example s=\"Betting is not a good idea\" findDouble(s) returns 2\n",
"
Define a function **findLastDouble** which takes as parameter a string and finds the last position of two identical characters, returning -1 if there are none.\n",
"
For example s=\"Betting is not a good idea\" findLastDouble(s) returns 18\n",
"