{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Python \n", "\n", "### Function Exercises" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1) Write a function that takes an integer representing minutes and converts it to seconds. (EASY)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 2) Create a function that converts a date formatted as MM/DD/YYYY to YYYYDDMM. The input is a string! \n", "\n", "(do not use datetime module)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 3) A typical car can hold four passengers and one driver, allowing five people to travel around. Given n number of people, `return` how many cars are needed to seat everyone comfortably." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 4) Create a function that replaces all the vowels in a string with the character '#'." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 5) Write a function that inverts the keys and values of a dictionary." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 6) Create a function that takes a list of strings and return a list, sorted from shortest to longest." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 7) Create a function that receives two list as parameters, and returns True if the first list is a subset of the second, or False otherwise. Do not use sets." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 8) Create a function that takes an integer and returns the factorial of that integer. That is, the integer multiplied by all positive lower integers." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 9) Create a function that takes a number as an argument and returns how many times it is multiple of 3." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 10) Create a function that sorts a list and removes all duplicate items from it. (Don't use 'set')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 11) Create a function that checks if the number is even or odd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 12) Create a function that receives a list, an element, a position and add the element in the given position in the list. This list is going to be the output of the function. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 13) Create a function that receives multiple parameters and returns a list with all the parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 14) Given a string, create a function that finds every word that contains a letter given as a parameter" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 15) [Project Euler problem #17](https://projecteuler.net/index.php?section=problems&id=17) \n", "\n", "If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.\n", "If all the numbers from 1 to 1000 (one thousand, inclusive) were written out in words, how many letters would be used?\n", "\n", "NOTE: Do not count spaces or hyphens. For example, the number 342 (three hundred and forty-two) contains 23 letters and the number 115 (one hundred and fifteen) contains 20 letters. The use of \"and\" when writing out numbers is in compliance with British usage.\n", "\n", "Hint: Create a function (or a set of functions) that receives an integer and returns it in \"written_form\".\n", "\n", "Example: \n", "\n", " print(written_number(234)) \n", " > 'two hundred and thirty-four' " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 16) [Project Euler problem #19](https://projecteuler.net/index.php?section=problems&id=1) \n", "\n", "\"Counting Sundays\"\n", "- 1 Jan 1900 was a Monday. \n", "- Thirty days has September,\n", "April, June and November.\n", "- All the rest have thirty-one,\n", "- Saving February alone, which has twenty-eight, rain or shine.\n", "- And on leap years, twenty-nine.\n", "- A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.\n", "\n", "\n", "How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }