{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Funções"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def soma(a,b):\n",
    "    print(a+b)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "soma(2,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def EPar(x):\n",
    "    return (x%2==0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EPar(13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EPar(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math as mt #importa o pacote math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def AreaTr(a,b,c):\n",
    "    s=(a+b+c)  #semiperímetro Formula de Heron\n",
    "    A=mt.sqrt(s*(s-a)*(s-b)*(s-c))\n",
    "    return A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "257.93022312245614\n"
     ]
    }
   ],
   "source": [
    "print(AreaTr(4,8,10))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__doc__',\n",
       " '__file__',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__spec__',\n",
       " 'acos',\n",
       " 'acosh',\n",
       " 'asin',\n",
       " 'asinh',\n",
       " 'atan',\n",
       " 'atan2',\n",
       " 'atanh',\n",
       " 'ceil',\n",
       " 'comb',\n",
       " 'copysign',\n",
       " 'cos',\n",
       " 'cosh',\n",
       " 'degrees',\n",
       " 'dist',\n",
       " 'e',\n",
       " 'erf',\n",
       " 'erfc',\n",
       " 'exp',\n",
       " 'expm1',\n",
       " 'fabs',\n",
       " 'factorial',\n",
       " 'floor',\n",
       " 'fmod',\n",
       " 'frexp',\n",
       " 'fsum',\n",
       " 'gamma',\n",
       " 'gcd',\n",
       " 'hypot',\n",
       " 'inf',\n",
       " 'isclose',\n",
       " 'isfinite',\n",
       " 'isinf',\n",
       " 'isnan',\n",
       " 'isqrt',\n",
       " 'ldexp',\n",
       " 'lgamma',\n",
       " 'log',\n",
       " 'log10',\n",
       " 'log1p',\n",
       " 'log2',\n",
       " 'modf',\n",
       " 'nan',\n",
       " 'perm',\n",
       " 'pi',\n",
       " 'pow',\n",
       " 'prod',\n",
       " 'radians',\n",
       " 'remainder',\n",
       " 'sin',\n",
       " 'sinh',\n",
       " 'sqrt',\n",
       " 'tan',\n",
       " 'tanh',\n",
       " 'tau',\n",
       " 'trunc']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(mt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120\n"
     ]
    }
   ],
   "source": [
    "def fatorial(n):\n",
    "    fat=1\n",
    "    while n>1:\n",
    "        fat *=n\n",
    "        n -= 1\n",
    "    return fat\n",
    "print(fatorial(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120\n"
     ]
    }
   ],
   "source": [
    "def fatorial(n):\n",
    "    if n==0 or n==1:\n",
    "        return 1\n",
    "    else:\n",
    "        return n*fatorial(n-1)\n",
    "          \n",
    "\n",
    "print(fatorial(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def barra(n=30, caractere='*'): #valores default\n",
    "    print(caractere*n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "******************************\n"
     ]
    }
   ],
   "source": [
    "barra()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "**********\n"
     ]
    }
   ],
   "source": [
    "barra(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==================================================\n"
     ]
    }
   ],
   "source": [
    "barra(50,\"=\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def soma(*args): #não é ponteiro, significa que pode ter vários argumentos\n",
    "    s=0\n",
    "    for x in args:\n",
    "        s +=x\n",
    "    return s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "print(soma(1,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87\n"
     ]
    }
   ],
   "source": [
    "print(soma(1,4, 32,50))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maior:  5\n",
      "Max: 9\n"
     ]
    }
   ],
   "source": [
    "def imprimeMaior(mensagem,*numeros): #mensagem é obrigatorio \n",
    "    maior = None  #None quer dizer vazio ou nada\n",
    "    for e in numeros: #para cada elemento e da lista de numeros faça\n",
    "        if maior==None or maior < e:\n",
    "            maior = e\n",
    "    print(mensagem, maior)\n",
    "\n",
    "imprimeMaior(\"Maior: \",5,4,3,2,1)\n",
    "imprimeMaior(\"Max:\", *[1,7,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximo:  None\n"
     ]
    }
   ],
   "source": [
    "imprimeMaior(\"Maximo: \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Funções Lambda"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "a=lambda x: x*2\n",
    "print(a(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.0\n"
     ]
    }
   ],
   "source": [
    "aumento=lambda a,b:(a*b/100)\n",
    "print(aumento(100,5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Arquivos\n",
    "#### Entrada e saída"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Modo de abertura dos arquivos\n",
    "Modo       Operação\n",
    "\n",
    "'r'       leitura\n",
    "\n",
    "'w'       escrita, apaga o conteudo se existir\n",
    "\n",
    "'a'       escreve no fim, preserva conteudo, se existir\n",
    "\n",
    "'b'       modo binario\n",
    "\n",
    "'+'       atualização (leitura e escrita)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Criando e gravando"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "arquivo=open(\"numeros.txt\",\"w\")\n",
    "for linha in range (1,101):\n",
    "    arquivo.write(\"%d\\n\" %linha)\n",
    "arquivo.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "_io.TextIOWrapper"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(arquivo)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lendo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "numeros.txt  \u001b[0m\u001b[01;32mroleta.txt\u001b[0m*\n"
     ]
    }
   ],
   "source": [
    "ls *.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "\n",
      "2\n",
      "\n",
      "3\n",
      "\n",
      "4\n",
      "\n",
      "5\n",
      "\n",
      "6\n",
      "\n",
      "7\n",
      "\n",
      "8\n",
      "\n",
      "9\n",
      "\n",
      "10\n",
      "\n",
      "11\n",
      "\n",
      "12\n",
      "\n",
      "13\n",
      "\n",
      "14\n",
      "\n",
      "15\n",
      "\n",
      "16\n",
      "\n",
      "17\n",
      "\n",
      "18\n",
      "\n",
      "19\n",
      "\n",
      "20\n",
      "\n",
      "21\n",
      "\n",
      "22\n",
      "\n",
      "23\n",
      "\n",
      "24\n",
      "\n",
      "25\n",
      "\n",
      "26\n",
      "\n",
      "27\n",
      "\n",
      "28\n",
      "\n",
      "29\n",
      "\n",
      "30\n",
      "\n",
      "31\n",
      "\n",
      "32\n",
      "\n",
      "33\n",
      "\n",
      "34\n",
      "\n",
      "35\n",
      "\n",
      "36\n",
      "\n",
      "37\n",
      "\n",
      "38\n",
      "\n",
      "39\n",
      "\n",
      "40\n",
      "\n",
      "41\n",
      "\n",
      "42\n",
      "\n",
      "43\n",
      "\n",
      "44\n",
      "\n",
      "45\n",
      "\n",
      "46\n",
      "\n",
      "47\n",
      "\n",
      "48\n",
      "\n",
      "49\n",
      "\n",
      "50\n",
      "\n",
      "51\n",
      "\n",
      "52\n",
      "\n",
      "53\n",
      "\n",
      "54\n",
      "\n",
      "55\n",
      "\n",
      "56\n",
      "\n",
      "57\n",
      "\n",
      "58\n",
      "\n",
      "59\n",
      "\n",
      "60\n",
      "\n",
      "61\n",
      "\n",
      "62\n",
      "\n",
      "63\n",
      "\n",
      "64\n",
      "\n",
      "65\n",
      "\n",
      "66\n",
      "\n",
      "67\n",
      "\n",
      "68\n",
      "\n",
      "69\n",
      "\n",
      "70\n",
      "\n",
      "71\n",
      "\n",
      "72\n",
      "\n",
      "73\n",
      "\n",
      "74\n",
      "\n",
      "75\n",
      "\n",
      "76\n",
      "\n",
      "77\n",
      "\n",
      "78\n",
      "\n",
      "79\n",
      "\n",
      "80\n",
      "\n",
      "81\n",
      "\n",
      "82\n",
      "\n",
      "83\n",
      "\n",
      "84\n",
      "\n",
      "85\n",
      "\n",
      "86\n",
      "\n",
      "87\n",
      "\n",
      "88\n",
      "\n",
      "89\n",
      "\n",
      "90\n",
      "\n",
      "91\n",
      "\n",
      "92\n",
      "\n",
      "93\n",
      "\n",
      "94\n",
      "\n",
      "95\n",
      "\n",
      "96\n",
      "\n",
      "97\n",
      "\n",
      "98\n",
      "\n",
      "99\n",
      "\n",
      "100\n",
      "\n"
     ]
    }
   ],
   "source": [
    "arquivo=open(\"numeros.txt\",\"r\") #abrindo para leitura\n",
    "for linha in arquivo.readlines():  #readlines lê todas as linhas, readline lê uma linha por vez\n",
    "    print(linha)\n",
    "arquivo.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['_CHUNK_SIZE',\n",
       " '__class__',\n",
       " '__del__',\n",
       " '__delattr__',\n",
       " '__dict__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__enter__',\n",
       " '__eq__',\n",
       " '__exit__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__lt__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__next__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__setattr__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " '_checkClosed',\n",
       " '_checkReadable',\n",
       " '_checkSeekable',\n",
       " '_checkWritable',\n",
       " '_finalizing',\n",
       " 'buffer',\n",
       " 'close',\n",
       " 'closed',\n",
       " 'detach',\n",
       " 'encoding',\n",
       " 'errors',\n",
       " 'fileno',\n",
       " 'flush',\n",
       " 'isatty',\n",
       " 'line_buffering',\n",
       " 'mode',\n",
       " 'name',\n",
       " 'newlines',\n",
       " 'read',\n",
       " 'readable',\n",
       " 'readline',\n",
       " 'readlines',\n",
       " 'reconfigure',\n",
       " 'seek',\n",
       " 'seekable',\n",
       " 'tell',\n",
       " 'truncate',\n",
       " 'writable',\n",
       " 'write',\n",
       " 'write_through',\n",
       " 'writelines']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(arquivo)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## arquivo.readlines() lê todas as linhas\n",
    "## arquivo.readline() lê linha"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lendo parâmetros na linha de comando"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Numero de parametros: 3\n",
      "Parametro 0 = /opt/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py\n",
      "Parametro 1 = -f\n",
      "Parametro 2 = /run/user/1000/jupyter/kernel-1088e419-8e03-4ee0-b783-fc704fbd298c.json\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print(\"Numero de parametros: %d\" %len(sys.argv))\n",
    "for n,p in enumerate(sys.argv):\n",
    "    print(\"Parametro %d = %s\" %(n,p))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Usando o pacote Pickle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Serve para salvar objetos do jeito que estão"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "Meuarquivo=open('test.pck','wb') # se colocar no 3.x só 'w' dará erro ao gravar\n",
    "pickle.dump(12.3,Meuarquivo)     #despeja (grava) um float em Meuarquivo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "pickle.dump([1,2,3],Meuarquivo) #despeja uma lista contendo 1,2 e 3\n",
    "Meuarquivo.close()              "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Salvou um tipo float e um tipo lista"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "MeuArquivo=open('test.pck','rb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "x=pickle.load(MeuArquivo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.3"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "y=pickle.load(MeuArquivo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['ADDITEMS',\n",
       " 'APPEND',\n",
       " 'APPENDS',\n",
       " 'BINBYTES',\n",
       " 'BINBYTES8',\n",
       " 'BINFLOAT',\n",
       " 'BINGET',\n",
       " 'BININT',\n",
       " 'BININT1',\n",
       " 'BININT2',\n",
       " 'BINPERSID',\n",
       " 'BINPUT',\n",
       " 'BINSTRING',\n",
       " 'BINUNICODE',\n",
       " 'BINUNICODE8',\n",
       " 'BUILD',\n",
       " 'DEFAULT_PROTOCOL',\n",
       " 'DICT',\n",
       " 'DUP',\n",
       " 'EMPTY_DICT',\n",
       " 'EMPTY_LIST',\n",
       " 'EMPTY_SET',\n",
       " 'EMPTY_TUPLE',\n",
       " 'EXT1',\n",
       " 'EXT2',\n",
       " 'EXT4',\n",
       " 'FALSE',\n",
       " 'FLOAT',\n",
       " 'FRAME',\n",
       " 'FROZENSET',\n",
       " 'FunctionType',\n",
       " 'GET',\n",
       " 'GLOBAL',\n",
       " 'HIGHEST_PROTOCOL',\n",
       " 'INST',\n",
       " 'INT',\n",
       " 'LIST',\n",
       " 'LONG',\n",
       " 'LONG1',\n",
       " 'LONG4',\n",
       " 'LONG_BINGET',\n",
       " 'LONG_BINPUT',\n",
       " 'MARK',\n",
       " 'MEMOIZE',\n",
       " 'NEWFALSE',\n",
       " 'NEWOBJ',\n",
       " 'NEWOBJ_EX',\n",
       " 'NEWTRUE',\n",
       " 'NONE',\n",
       " 'OBJ',\n",
       " 'PERSID',\n",
       " 'POP',\n",
       " 'POP_MARK',\n",
       " 'PROTO',\n",
       " 'PUT',\n",
       " 'PickleError',\n",
       " 'Pickler',\n",
       " 'PicklingError',\n",
       " 'PyStringMap',\n",
       " 'REDUCE',\n",
       " 'SETITEM',\n",
       " 'SETITEMS',\n",
       " 'SHORT_BINBYTES',\n",
       " 'SHORT_BINSTRING',\n",
       " 'SHORT_BINUNICODE',\n",
       " 'STACK_GLOBAL',\n",
       " 'STOP',\n",
       " 'STRING',\n",
       " 'TRUE',\n",
       " 'TUPLE',\n",
       " 'TUPLE1',\n",
       " 'TUPLE2',\n",
       " 'TUPLE3',\n",
       " 'UNICODE',\n",
       " 'Unpickler',\n",
       " 'UnpicklingError',\n",
       " '_Framer',\n",
       " '_Pickler',\n",
       " '_Stop',\n",
       " '_Unframer',\n",
       " '_Unpickler',\n",
       " '__all__',\n",
       " '__builtins__',\n",
       " '__cached__',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__spec__',\n",
       " '_compat_pickle',\n",
       " '_dump',\n",
       " '_dumps',\n",
       " '_extension_cache',\n",
       " '_extension_registry',\n",
       " '_getattribute',\n",
       " '_inverted_registry',\n",
       " '_load',\n",
       " '_loads',\n",
       " '_test',\n",
       " '_tuplesize2code',\n",
       " 'bytes_types',\n",
       " 'codecs',\n",
       " 'compatible_formats',\n",
       " 'decode_long',\n",
       " 'dispatch_table',\n",
       " 'dump',\n",
       " 'dumps',\n",
       " 'encode_long',\n",
       " 'format_version',\n",
       " 'io',\n",
       " 'islice',\n",
       " 'load',\n",
       " 'loads',\n",
       " 'maxsize',\n",
       " 'pack',\n",
       " 'partial',\n",
       " 're',\n",
       " 'sys',\n",
       " 'unpack',\n",
       " 'whichmodule']"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(pickle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Criando duas funções\n",
    "\n",
    "# Função 1 - Recebe uma temperatura como parâmetro e retorna a temperatura em Fahrenheit\n",
    "def fahrenheit(T):\n",
    "    return ((float(9)/5)*T + 32)\n",
    "\n",
    "# Função 2 - Recebe uma temperatura como parâmetro e retorna a temperatura em Celsius\n",
    "def celsius(T):\n",
    "    return (float(5)/9)*(T-32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Criando uma lista\n",
    "temperaturas = [0, 22.5, 40, 100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<map at 0x7f33143b0a60>"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Aplicando a função a cada elemento da lista de temperaturas. \n",
    "# Em Python 3, a funçãp map() retornar um iterator\n",
    "map(fahrenheit, temperaturas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[32.0, 72.5, 104.0, 212.0]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list (map(fahrenheit,temperaturas))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ver PythonFundamentos-master-Cap04-05 pasta Notebook\n",
    "### Ver PythonFundamentos-master-Cap04-06 pasta Notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
