├── CAPÍTULO_10_DATAREADER_E_ANÁLISES_COM_YAHOO!_FINANCE.ipynb
├── CAPÍTULO_11_PROCESSAMENTO_EM_PARALELO.ipynb
├── CAPÍTULO_12_GOOGLE_TRENDS_E_MERCADO_FINANCEIRO.ipynb
├── CAPÍTULO_13_INTELIGÊNCIA_ARTIFICIAL_NO_GOOGLE.ipynb
├── CAPÍTULO_1_PRINCÍPIOS_DE_PROGRAMAÇÃO.ipynb
├── CAPÍTULO_2_ITERAÇÃO_E_DECISÃO.ipynb
├── CAPÍTULO_3_EXPLORAÇÃO_A_ESTATÍSTICA_NO_MERCADO.ipynb
├── CAPÍTULO_4_GRÁFICOS_PARA_ANÁLISES_E_OPERAÇÕES.ipynb
├── CAPÍTULO_5_PROGRAMANDO_FUNÇÕES.ipynb
├── CAPÍTULO_6_A_DINÃMICA_DO_ARRAY.ipynb
├── CAPÍTULO_7_AS_BIBLIOTECAS_TIME_E_DATETIME.ipynb
├── CAPÍTULO_8_A_BIBLIOTECA_PANDAS.ipynb
├── CAPÍTULO_9_FINANÇAS_E_PYTHON.ipynb
├── Dados
├── Capítulo 1
│ ├── Dados_vale__Gerdau.xlsx
│ ├── Petrobras.xlsx
│ └── bov.txt
├── Capítulo 3
│ ├── BitCoin.xlsx
│ ├── Dow Jones.xlsx
│ ├── ExPy.xlsx
│ ├── ExercPy.xlsx
│ ├── IBOV x PETR4.xlsx
│ ├── Ibv.xlsx
│ ├── Ibv_Junto.xlsx
│ ├── ListaDupla.xlsx
│ ├── PETR4.xlsx
│ └── VALE3.xlsx
├── Capítulo 6
│ ├── Ibov.xlsx
│ ├── PetrTitul.xlsx
│ └── Titulos.xlsx
├── Capítulo 7
│ ├── BBrasil_intra.xlsx
│ ├── Dados 7.4 - 2.xlsx
│ ├── Vale3.xlsx
│ ├── cotação.txt
│ └── datas.txt
├── Capítulo 8
│ ├── Book_Ex.xlsx
│ ├── Grupos.xlsx
│ └── Ibv_crise_2008.xlsx
└── Capítulo 9
│ ├── BBrasil.xlsx
│ ├── Bov2008.xlsx
│ ├── Ibovespa.xlsx
│ ├── OpcaoSmile.xlsx
│ ├── Portfolio_Bov.xlsx
│ ├── Portfolio_Moedas.xlsx
│ └── Portfolio_Moedas.xlsx.txt
├── LICENSE
└── README.md
/CAPÍTULO_10_DATAREADER_E_ANÁLISES_COM_YAHOO!_FINANCE.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "toc_visible": true,
8 | "authorship_tag": "ABX9TyN1es8y6Meu5eFu1JXx58tm",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | },
15 | "language_info": {
16 | "name": "python"
17 | }
18 | },
19 | "cells": [
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {
23 | "id": "view-in-github",
24 | "colab_type": "text"
25 | },
26 | "source": [
27 | "
"
28 | ]
29 | },
30 | {
31 | "cell_type": "markdown",
32 | "source": [
33 | "#CAPÍTULO 10 - DATAREADER E ANÁLISES COM YAHOO! FINANCE"
34 | ],
35 | "metadata": {
36 | "id": "lPO8eOeNzk0J"
37 | }
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "source": [
42 | "#Explicação"
43 | ],
44 | "metadata": {
45 | "id": "LDZm6VgYqRIp"
46 | }
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "source": [
51 | "##10.3 CÁLCULOS COM JANELAS MÓVEIS (ROLLING METHOD) - Explicação\n"
52 | ],
53 | "metadata": {
54 | "id": "oUA5qpbezyQz"
55 | }
56 | },
57 | {
58 | "cell_type": "code",
59 | "source": [
60 | "pip install pandas_datareader"
61 | ],
62 | "metadata": {
63 | "colab": {
64 | "base_uri": "https://localhost:8080/"
65 | },
66 | "id": "a01Ax2ia1A6X",
67 | "outputId": "b80cbdf9-5d82-41e6-8b7b-aa38b5f8a1ec"
68 | },
69 | "execution_count": 2,
70 | "outputs": [
71 | {
72 | "output_type": "stream",
73 | "name": "stdout",
74 | "text": [
75 | "Requirement already satisfied: pandas_datareader in /usr/local/lib/python3.10/dist-packages (0.10.0)\n",
76 | "Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from pandas_datareader) (4.9.3)\n",
77 | "Requirement already satisfied: pandas>=0.23 in /usr/local/lib/python3.10/dist-packages (from pandas_datareader) (1.5.3)\n",
78 | "Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.10/dist-packages (from pandas_datareader) (2.31.0)\n",
79 | "Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.23->pandas_datareader) (2.8.2)\n",
80 | "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.23->pandas_datareader) (2023.3.post1)\n",
81 | "Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.23->pandas_datareader) (1.23.5)\n",
82 | "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->pandas_datareader) (3.2.0)\n",
83 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->pandas_datareader) (3.4)\n",
84 | "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->pandas_datareader) (2.0.4)\n",
85 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->pandas_datareader) (2023.7.22)\n",
86 | "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas>=0.23->pandas_datareader) (1.16.0)\n"
87 | ]
88 | }
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": null,
94 | "metadata": {
95 | "id": "AR0qElGkzOLE"
96 | },
97 | "outputs": [],
98 | "source": [
99 | "# 10.3 CÁLCULOS COM JANELAS MÓVEIS (ROLLING METHOD) - Explicação\n",
100 | "# Servidor Yahoo está fora\n",
101 | "\n",
102 | "################################################################\n",
103 | "# #\n",
104 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
105 | "# pip install pandas_datareader #\n",
106 | "# #\n",
107 | "################################################################\n",
108 | "\n",
109 | "import matplotlib.pyplot as fig\n",
110 | "import datetime as dt\n",
111 | "import pandas_datareader.data as web\n",
112 | "\n",
113 | "inicio = dt.datetime(2015,1,1)\n",
114 | "fim = dt.datetime(2019,11,24)\n",
115 | "df = web.DataReader('^BVSP','yahoo',inicio,fim)\n",
116 | "df['Close'].plot(color='K',lw=2,alpha=0.6)\n",
117 | "df['med_mov'] = df['Close'].rolling(window=150,min_periods=0).mean()\n",
118 | "df['med_mov'] .plot(color='k',lw=3,style='--')\n",
119 | "\n",
120 | "fig.grid()\n",
121 | "fig.title('Ibovespa (2015-2019)',fontsize=18,weight='bold')\n",
122 | "fig.legend('Ibovespa','Média Móvel 150 dias')"
123 | ]
124 | },
125 | {
126 | "cell_type": "markdown",
127 | "source": [
128 | "##10.4 VISUALIZAÇÃO COM CANDLESTICK DA BIBLIOTECA MPL_FINANCE - Explicação 1\n"
129 | ],
130 | "metadata": {
131 | "id": "9ZyfkaT1z3mr"
132 | }
133 | },
134 | {
135 | "cell_type": "code",
136 | "source": [
137 | "pip install MPL-FINANCE"
138 | ],
139 | "metadata": {
140 | "colab": {
141 | "base_uri": "https://localhost:8080/"
142 | },
143 | "id": "z9u6ufGx1F5t",
144 | "outputId": "4f7c288e-0de5-427c-f1af-b37182334784"
145 | },
146 | "execution_count": 4,
147 | "outputs": [
148 | {
149 | "output_type": "stream",
150 | "name": "stdout",
151 | "text": [
152 | "Collecting MPL-FINANCE\n",
153 | " Downloading mpl_finance-0.10.1-py3-none-any.whl (8.4 kB)\n",
154 | "Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from MPL-FINANCE) (3.7.1)\n",
155 | "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (1.1.0)\n",
156 | "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (0.11.0)\n",
157 | "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (4.42.1)\n",
158 | "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (1.4.5)\n",
159 | "Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (1.23.5)\n",
160 | "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (23.1)\n",
161 | "Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (9.4.0)\n",
162 | "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (3.1.1)\n",
163 | "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->MPL-FINANCE) (2.8.2)\n",
164 | "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib->MPL-FINANCE) (1.16.0)\n",
165 | "Installing collected packages: MPL-FINANCE\n",
166 | "Successfully installed MPL-FINANCE-0.10.1\n"
167 | ]
168 | }
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "source": [
174 | "# 10.4 VISUALIZAÇÃO COM CANDLESTICK DA BIBLIOTECA MPL_FINANCE - Explicação 1\n",
175 | "# Servidor Yahoo está fora\n",
176 | "\n",
177 | "################################################################\n",
178 | "# #\n",
179 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
180 | "# >> pip install pandas_datareader #\n",
181 | "# Para usar o candles precisa instalar o mpl_finance: #\n",
182 | "# >> pip install MPL-FINANCE #\n",
183 | "################################################################\n",
184 | "\n",
185 | "import matplotlib.pyplot as fig\n",
186 | "import datetime as dt\n",
187 | "from mpl_finance import candlestick_ohlc\n",
188 | "import matplotlib.dates as mdates\n",
189 | "import pandas_datareader.data as web\n",
190 | "\n",
191 | "inicio = dt.datetime(2019,1,1)\n",
192 | "fim = dt.datetime(2019,11,27)\n",
193 | "df = web.DataReader('^bvsp','yahoo',inicio,fim)\n",
194 | "#++++++++++++ Amostragem para os candles ++++++++++++++++++++++++++++\n",
195 | "df_ohlc = df['Close'].resample('7D').ohlc()\n",
196 | "df_ohlc.reset_index(inplace = True)\n",
197 | "df_ohlc['Date'] = df_ohlc['Date'].map(mdates.date2num)\n",
198 | "\n",
199 | "ax1 = fig.subplot(111)\n",
200 | "\n",
201 | "ax1.xaxis_date()\n",
202 | "\n",
203 | "candlestick_ohlc(ax1,df_ohlc.values, width=2, colorup=2, colordown='gray')\n",
204 | "ax1.set_xlabel('DATA',fontsize=16)\n",
205 | "ax1.set_ylabel('IBOVESPA',fontsize=16)\n",
206 | "fig.grid()"
207 | ],
208 | "metadata": {
209 | "id": "Q4Qx_BnPz-W3"
210 | },
211 | "execution_count": null,
212 | "outputs": []
213 | },
214 | {
215 | "cell_type": "markdown",
216 | "source": [
217 | "##10.4 VISUALIZAÇÃO COM CANDLESTICK DA BIBLIOTECA MPL_FINANCE - Explicação 2\n"
218 | ],
219 | "metadata": {
220 | "id": "Sp1kX9qX0FU7"
221 | }
222 | },
223 | {
224 | "cell_type": "code",
225 | "source": [
226 | "# 10.4 VISUALIZAÇÃO COM CANDLESTICK DA BIBLIOTECA MPL_FINANCE - Explicação 2\n",
227 | "# Servidor Yahoo está fora\n",
228 | "\n",
229 | "################################################################\n",
230 | "# #\n",
231 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
232 | "# >> pip install pandas_datareader #\n",
233 | "# Para usar o candles precisa instalar o mpl_finance: #\n",
234 | "# >> pip install MPL-FINANCE #\n",
235 | "################################################################\n",
236 | "\n",
237 | "import matplotlib.pyplot as fig\n",
238 | "import datetime as dt\n",
239 | "from mpl_finance import candlestick_ohlc\n",
240 | "import matplotlib.dates as mdates\n",
241 | "import pandas_datareader.data as web\n",
242 | "\n",
243 | "inicio = dt.datetime(2019,1,1)\n",
244 | "fim = dt.datetime(2019,11,27)\n",
245 | "df = web.DataReader('^bvsp','yahoo',inicio,fim)\n",
246 | "#++++++++++++ Amostragem para os candles ++++++++++++++++++++++++++++\n",
247 | "df_ohlc = df['Close'].resample('7D').ohlc()\n",
248 | "df_ohlc.reset_index(inplace = True)\n",
249 | "df_ohlc['Date'] = df_ohlc['Date'].map(mdates.date2num)\n",
250 | "df['med_mov'] = df['Close'].rolling(window=20,min_periods=0).mean()\n",
251 | "ax1 = fig.subplot(111)\n",
252 | "\n",
253 | "ax1.xaxis_date()\n",
254 | "\n",
255 | "candlestick_ohlc(ax1,df_ohlc.values, width=2, colorup='k', colordown='gray')\n",
256 | "ax1.plot(df.index,df['med_mov'],color='k')\n",
257 | "ax1.set_xlabel('DATA',fontsize=16)\n",
258 | "ax1.set_ylabel('IBOVESPA',fontsize=16)"
259 | ],
260 | "metadata": {
261 | "id": "dGYSM5VK0IpA"
262 | },
263 | "execution_count": null,
264 | "outputs": []
265 | },
266 | {
267 | "cell_type": "markdown",
268 | "source": [
269 | "##10.4 VISUALIZAÇÃO COM CANDLESTICK DA BIBLIOTECA MPL_FINANCE - Explicação 3"
270 | ],
271 | "metadata": {
272 | "id": "a14zBvim0NHa"
273 | }
274 | },
275 | {
276 | "cell_type": "code",
277 | "source": [
278 | "# 10.4 VISUALIZAÇÃO COM CANDLESTICK DA BIBLIOTECA MPL_FINANCE - Explicação 3\n",
279 | "# Servidor Yahoo está fora\n",
280 | "\n",
281 | "################################################################\n",
282 | "# #\n",
283 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
284 | "# >> pip install pandas_datareader #\n",
285 | "# Para usar o candles precisa instalar o mpl_finance: #\n",
286 | "# >> pip install MPL-FINANCE #\n",
287 | "################################################################\n",
288 | "\n",
289 | "import numpy as np\n",
290 | "import matplotlib.pyplot as fig\n",
291 | "import datetime as dt\n",
292 | "from mpl_finance import candlestick_ohlc\n",
293 | "import matplotlib.dates as mdates\n",
294 | "import pandas as pd\n",
295 | "import pandas_datareader.data as web\n",
296 | "import matplotlib.mlab as mlab\n",
297 | "\n",
298 | "\n",
299 | "inicio = dt.datetime(2019,1,1)\n",
300 | "fim = dt.datetime(2019,11,27)\n",
301 | "df = web.DataReader('^bvsp','yahoo',inicio,fim)\n",
302 | "\n",
303 | "lin = df['Close'].count()\n",
304 | "x = np.zeros(lin)\n",
305 | "for i in range(lin):\n",
306 | " x[i] = df['Close'][i]\n",
307 | "\n",
308 | "retorno = (x[1:lin]-x[0:lin-1])/x[0:lin-1]\n",
309 | "df2 = pd.Dataframe(columns=[])\n",
310 | "df2['Retorno'] = retorno\n",
311 | "#+++++++++++++++++++++++++ Histograma +++++++++++++++++++++++++++++++\n",
312 | "ax3 = fig.subplot(223)\n",
313 | "[n,bins,patches]= ax3.hist(retorno,bins=30,normed=True)\n",
314 | "mu = np.mean(retorno)\n",
315 | "sigma = np.std(retorno)\n",
316 | "dist_norm = mlab.normpdf(bins,mu,sigma)\n",
317 | "ax3.plot(bins,dist_norm)\n",
318 | "ax3.set_title('Histograma dos retornos', fontsize =16)\n",
319 | "#+++++++++++++++++++++ BOX-PLOT +++++++++++++++++++++++++++++++++++++\n",
320 | "ax4 = fig.subplot(224)\n",
321 | "for i in range(len(retorno)):\n",
322 | " d = ax4.boxplot(df2.retorno[1+i:20+i],position=[i],\n",
323 | " showfliers=False,patch_artist=True,\n",
324 | " boxprops=dict(facecolor=\"C0\", color=\"C1\"))\n",
325 | "ax4.set_xlim(0,len(retorno))\n",
326 | "ax4.set_title('Box-plot dos retornos', fontsize=16)\n",
327 | "fig.tight_layout()"
328 | ],
329 | "metadata": {
330 | "id": "2g7keGwO0RHT"
331 | },
332 | "execution_count": null,
333 | "outputs": []
334 | },
335 | {
336 | "cell_type": "markdown",
337 | "source": [
338 | "##10.5 DADOS COM BIBLIOTECA REQUESTS PARA TICKER-BY-TICKER - Explicação 1\n"
339 | ],
340 | "metadata": {
341 | "id": "s35dk1al0aFx"
342 | }
343 | },
344 | {
345 | "cell_type": "code",
346 | "source": [
347 | "# 10.5 DADOS COM BIBLIOTECA REQUESTS PARA TICKER-BY-TICKER - Explicação 1\n",
348 | "\n",
349 | "################################################################\n",
350 | "# PRECISA INSTALAR ANTES yahoo_fin\n",
351 | "#\n",
352 | "# >> pip install requests_html\n",
353 | "# >> pip install yahoo_fin\n",
354 | "################################################################\n",
355 | "\n",
356 | "from yahoo_fin.stock_info import *\n",
357 | "import numpy as np\n",
358 | "import time\n",
359 | "import matplotlib.pyplot as fig\n",
360 | "import datetime as dt\n",
361 | "from mpl_finance import candlestick_ohlc\n",
362 | "import matplotlib.dates as mdates\n",
363 | "import pandas as pd\n",
364 | "import pandas_datareader.data as web\n",
365 | "import matplotlib.mlab as mlab\n",
366 | "\n",
367 | "lin = 10\n",
368 | "x = np.zeros(lin)\n",
369 | "\n",
370 | "for i in range(lin):\n",
371 | " x[i] = get_live_price(\"PETR4.SA\")\n",
372 | " print(i,round(x[i],2))\n",
373 | " time.sleep(5)"
374 | ],
375 | "metadata": {
376 | "id": "MGM9muEf0dPx"
377 | },
378 | "execution_count": null,
379 | "outputs": []
380 | },
381 | {
382 | "cell_type": "markdown",
383 | "source": [
384 | "##10.5 DADOS COM BIBLIOTECA REQUESTS PARA TICKER-BY-TICKER - Explicação 2\n"
385 | ],
386 | "metadata": {
387 | "id": "TdJGSTuC0hJ9"
388 | }
389 | },
390 | {
391 | "cell_type": "code",
392 | "source": [
393 | "# 10.5 DADOS COM BIBLIOTECA REQUESTS PARA TICKER-BY-TICKER - Explicação 2\n",
394 | "\n",
395 | "################################################################\n",
396 | "# PRECISA INSTALAR ANTES yahoo_fin\n",
397 | "#\n",
398 | "# >> pip install requests_html\n",
399 | "# >> pip install yahoo_fin\n",
400 | "################################################################\n",
401 | "\n",
402 | "from yahoo_fin.stock_info import *\n",
403 | "import numpy as np\n",
404 | "import time\n",
405 | "import matplotlib.pyplot as fig\n",
406 | "import datetime as dt\n",
407 | "from mpl_finance import candlestick_ohlc\n",
408 | "import matplotlib.dates as mdates\n",
409 | "import pandas as pd\n",
410 | "import pandas_datareader.data as web\n",
411 | "import matplotlib.mlab as mlab\n",
412 | "\n",
413 | "lin = 50\n",
414 | "x = np.zeros(lin)\n",
415 | "y = np.zeros(lin)\n",
416 | "xar = []\n",
417 | "yar = []\n",
418 | "\n",
419 | "fig.style.use('ggplot')\n",
420 | "figura = fig.figure()\n",
421 | "\n",
422 | "ax1_din = fig.subplot(211)\n",
423 | "ax2_din = fig.subplot(212)\n",
424 | "\n",
425 | "for i in range(lin):\n",
426 | " x[i] = get_live_price(\"PETR4.SA\")\n",
427 | " y[i] = get_live_price(\"USIM5.SA\")\n",
428 | " print(i,round(x[i],2), round(y[i],2))\n",
429 | " xar.append(x[i])\n",
430 | " yar.append(y[i])\n",
431 | " ax1_din.plot(xar,'k')\n",
432 | " ax2_din.plot(yar,'k')\n",
433 | " fig.pause(0.5)\n",
434 | " time.sleep(10)\n",
435 | "\n",
436 | " ax1_din.set_title('PETR4')\n",
437 | " ax2_din.set_title('USIM5')"
438 | ],
439 | "metadata": {
440 | "id": "gFsTi8PU0ho1"
441 | },
442 | "execution_count": null,
443 | "outputs": []
444 | },
445 | {
446 | "cell_type": "markdown",
447 | "source": [
448 | "#Exemplos"
449 | ],
450 | "metadata": {
451 | "id": "895ch5jjsFtT"
452 | }
453 | },
454 | {
455 | "cell_type": "markdown",
456 | "source": [
457 | "##Exemplo 10.1"
458 | ],
459 | "metadata": {
460 | "id": "39mCeJDrsWxJ"
461 | }
462 | },
463 | {
464 | "cell_type": "code",
465 | "source": [
466 | "# Exemplo 10.1\n",
467 | "# Servidor Yahoo está fora\n",
468 | "\n",
469 | "################################################################\n",
470 | "# #\n",
471 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
472 | "# pip install pandas_datareader #\n",
473 | "# #\n",
474 | "################################################################\n",
475 | "\n",
476 | "import matplotlib.pyplot as fig\n",
477 | "import datetime as dt\n",
478 | "import pandas_datareader.data as web\n",
479 | "\n",
480 | "\n",
481 | "inicio = dt.datetime(2019,1,1)\n",
482 | "fim = dt.datetime(2019,11,24)\n",
483 | "df = web.DataReader('PETR4.SA', 'yahoo', inicio, fim)\n",
484 | "df['Close'].plot(color = 'k',lw = 4)\n",
485 | "fig.grid()\n",
486 | "fig.title('PETR4 (Jan - Nov / 2019)',fontsize = 18, weight= 'bold')"
487 | ],
488 | "metadata": {
489 | "id": "SFnLOPtg02M3"
490 | },
491 | "execution_count": 5,
492 | "outputs": []
493 | },
494 | {
495 | "cell_type": "markdown",
496 | "source": [
497 | "##Exemplo 10.2"
498 | ],
499 | "metadata": {
500 | "id": "OccgzXwL1UYV"
501 | }
502 | },
503 | {
504 | "cell_type": "code",
505 | "source": [
506 | "# Exemplo 10.2\n",
507 | "# Servidor Yahoo está fora\n",
508 | "\n",
509 | "################################################################\n",
510 | "# #\n",
511 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
512 | "# pip install pandas_datareader #\n",
513 | "# #\n",
514 | "################################################################\n",
515 | "\n",
516 | "import matplotlib.pyplot as fig\n",
517 | "import datetime as dt\n",
518 | "import pandas_datareader.data as web\n",
519 | "\n",
520 | "\n",
521 | "inicio = dt.datetime(2019,1,1)\n",
522 | "fim = dt.datetime(2019,11,24)\n",
523 | "df = web.DataReader('^bvsp', 'yahoo', inicio, fim)\n",
524 | "df['Close'].plot(color = 'k',lw = 4)\n",
525 | "fig.grid()\n",
526 | "fig.title('IBOVESPA (Jan - Nov / 2019)',fontsize = 18, weight= 'bold')"
527 | ],
528 | "metadata": {
529 | "id": "Kf1znq1L05kV"
530 | },
531 | "execution_count": null,
532 | "outputs": []
533 | },
534 | {
535 | "cell_type": "markdown",
536 | "source": [
537 | "##Exemplo 10.3"
538 | ],
539 | "metadata": {
540 | "id": "jnZO1SwY1a1N"
541 | }
542 | },
543 | {
544 | "cell_type": "code",
545 | "source": [
546 | "# Exemplo 10.3\n",
547 | "# Servidor Yahoo está fora\n",
548 | "\n",
549 | "################################################################\n",
550 | "# #\n",
551 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
552 | "# pip install pandas_datareader #\n",
553 | "# #\n",
554 | "################################################################\n",
555 | "\n",
556 | "import datetime as dt\n",
557 | "import pandas_datareader.data as web\n",
558 | "import seaborn as sns\n",
559 | "\n",
560 | "inicio = dt.datetime(2019,1,1)\n",
561 | "fim = dt.datetime(2019,11,24)\n",
562 | "df1 = web.DataReader('GGBR4.SA', 'yahoo', inicio, fim)\n",
563 | "df1['Data'] = df1.index\n",
564 | "df2 = web.DataReader('PETR4.SA', 'yahoo', inicio, fim)\n",
565 | "df2['Data'] = df2.index\n",
566 | "\n",
567 | "dados = sns.regplot(df1['Close'],df2['Close'],color= 'black')\n",
568 | "dados.set_xlabel('GGBR4', fontsize = 16)\n",
569 | "dados.set_ylabel('PETR4', fontsize = 16)\n",
570 | "\n",
571 | "dad_cond = sns.jointplot(df1['Close'], df2['Close'], kind = 'scatter', color = 'black')\n",
572 | "dad_cond.set_axis_labels('GGBR4','PETR4', fontsize = 16)"
573 | ],
574 | "metadata": {
575 | "id": "-e3oU0nD1b0v"
576 | },
577 | "execution_count": null,
578 | "outputs": []
579 | },
580 | {
581 | "cell_type": "markdown",
582 | "source": [
583 | "##Exemplo 10.4"
584 | ],
585 | "metadata": {
586 | "id": "6tDjJqm91qIj"
587 | }
588 | },
589 | {
590 | "cell_type": "code",
591 | "source": [
592 | "# Exemplo 10.4\n",
593 | "# Servidor Yahoo está fora\n",
594 | "\n",
595 | "import datetime as dt\n",
596 | "import pandas_datareader.data as web\n",
597 | "import matplotlib.pyplot as fig\n",
598 | "\n",
599 | "inicio = dt.datetime(2019,1,1)\n",
600 | "fim = dt.datetime(2019,11,24)\n",
601 | "acoes = ['GGBR4.SA','BBAS3.SA','PETR4.SA','USIM5.SA','ITUB4.SA']\n",
602 | "df = web.DataReader(acoes, 'yahoo', inicio, fim)\n",
603 | "df['Data'] = df.index\n",
604 | "\n",
605 | "dados = df['Close'].plot(style=['-','--','-o','-*','-d'],color='k',lw=1)\n",
606 | "dados.set_xlabel('Data',fontsize=16)\n",
607 | "dados.set_ylabel('Ações',fontsize=16)\n",
608 | "fig.grid()\n",
609 | "fig.title('AÇÕES (Jan-Nov / 2019)',fontsize = 18, weight = 'bold')"
610 | ],
611 | "metadata": {
612 | "id": "ZoEpb8NU1rMV"
613 | },
614 | "execution_count": null,
615 | "outputs": []
616 | },
617 | {
618 | "cell_type": "markdown",
619 | "source": [
620 | "##Exemplo 10.5"
621 | ],
622 | "metadata": {
623 | "id": "vVqlpNZk1vnJ"
624 | }
625 | },
626 | {
627 | "cell_type": "code",
628 | "source": [
629 | "# Exemplo 10.5\n",
630 | "# Servidor Yahoo está fora\n",
631 | "# Matrix scatter histograma 'kde'\n",
632 | "\n",
633 | "import datetime as dt\n",
634 | "import pandas_datareader.data as web\n",
635 | "import pandas as pd\n",
636 | "\n",
637 | "inicio = dt.datetime(2019,1,1)\n",
638 | "fim = dt.datetime(2019,11,24)\n",
639 | "acoes = ['GGBR4.SA','BBAS3.SA','PETR4.SA','USIM5.SA','ITUB4.SA']\n",
640 | "df = web.DataReader(acoes, 'yahoo', inicio, fim)\n",
641 | "retorno = df['Close'].pct_change()\n",
642 | "pd.plotting.scatter_matrix(retorno,diagonal='kde',alpha=0.8,color='black')"
643 | ],
644 | "metadata": {
645 | "id": "CjAvqnwT1wwf"
646 | },
647 | "execution_count": null,
648 | "outputs": []
649 | },
650 | {
651 | "cell_type": "code",
652 | "source": [
653 | "# Matrix scatter 'hist'\n",
654 | "\n",
655 | "import datetime as dt\n",
656 | "import pandas_datareader.data as web\n",
657 | "import pandas as pd\n",
658 | "\n",
659 | "inicio = dt.datetime(2019,1,1)\n",
660 | "fim = dt.datetime(2019,11,24)\n",
661 | "acoes = ['GGBR4.SA','BBAS3.SA','PETR4.SA','USIM5.SA','ITUB4.SA']\n",
662 | "df = web.DataReader(acoes, 'yahoo', inicio, fim)\n",
663 | "retorno = df['Close'].pct_change()\n",
664 | "pd.plotting.scatter_matrix(retorno,diagonal='hist',alpha=0.8,color='black')"
665 | ],
666 | "metadata": {
667 | "id": "15zLDZAc10XU"
668 | },
669 | "execution_count": null,
670 | "outputs": []
671 | },
672 | {
673 | "cell_type": "markdown",
674 | "source": [
675 | "##Exemplo 10.6"
676 | ],
677 | "metadata": {
678 | "id": "kNMhsN7315PC"
679 | }
680 | },
681 | {
682 | "cell_type": "code",
683 | "source": [
684 | "# Exemplo 10.6\n",
685 | "# Algoritmo para ajustamento de datas diferentes em arquivos\n",
686 | "\n",
687 | "import pandas as pd\n",
688 | "\n",
689 | "arq1=pd.Series([2,3,1,5],\n",
690 | " index=['1/12/2019','2/12/2019','3/12/2019','4/12/2019'])\n",
691 | "\n",
692 | "arq2=pd.Series([20,11,17],\n",
693 | " index=['1/12/2019','3/12/2019','4/12/2019'])\n",
694 | "#+++++++++++++ Pareamento de datas para o mesmo dia +++++++++++++++++\n",
695 | "intersect = arq2.index.intersection(arq1.index)\n",
696 | "arq1_mod=arq1.loc[intersect]\n",
697 | "arq2_mod=arq2.loc[intersect]\n",
698 | "print('++++++++++++++++++++++++++++++++++++++++++++++')\n",
699 | "print('Arquivo mod = ')\n",
700 | "print(arq1_mod)\n",
701 | "print('++++++++++++++++++++++++++++++++++++++++++++++')\n",
702 | "print('Arquivo mod = ')\n",
703 | "print(arq2_mod)"
704 | ],
705 | "metadata": {
706 | "id": "kspa4igP16Gi"
707 | },
708 | "execution_count": null,
709 | "outputs": []
710 | },
711 | {
712 | "cell_type": "markdown",
713 | "source": [
714 | "##Exemplo 10.7"
715 | ],
716 | "metadata": {
717 | "id": "S_SaourJ1_yR"
718 | }
719 | },
720 | {
721 | "cell_type": "code",
722 | "source": [
723 | "# Exemplo 10.7\n",
724 | "# Servidor Yahoo está fora\n",
725 | "\n",
726 | "################################################################\n",
727 | "# #\n",
728 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
729 | "# pip install pandas_datareader #\n",
730 | "# #\n",
731 | "################################################################\n",
732 | "\n",
733 | "import datetime as dt\n",
734 | "import pandas_datareader.data as web\n",
735 | "import seaborn as sns\n",
736 | "\n",
737 | "inicio = dt.datetime(2019,1,1)\n",
738 | "fim = dt.datetime(2019,11,24)\n",
739 | "\n",
740 | "df1 = web.DataReader('^bvsp','yahoo',inicio,fim)\n",
741 | "df2 = web.DataReader('^dji','yahoo',inicio,fim)\n",
742 | "#+++++++++++++++++ Pareamento de datas para o mesmo dia +++++++++\n",
743 | "intersect = df2.index.intersection(df1.index)\n",
744 | "bov = df1.loc[intersect]\n",
745 | "dow = df2.loc[intersect]\n",
746 | "#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
747 | "correcao = bov.corrwith(dow, axis = 0)\n",
748 | "dados = sns.regplot(bov['Close'],dow['Close'],color='black')\n",
749 | "\n",
750 | "dados.set_xlabel('IBOVESPA',fontsize=16)\n",
751 | "dados.set_ylabel('DOW JONES',fontsize=16)\n",
752 | "dados.set_title('Rgressão Linear Ibovespa x Dow Jones (Jan-Nov)/ 2019',\n",
753 | " fontsize=18)\n",
754 | "print('++++++++++++ Correção ++++++++++++')\n",
755 | "print(correcao)"
756 | ],
757 | "metadata": {
758 | "id": "l6p4uZ5j2A0k"
759 | },
760 | "execution_count": null,
761 | "outputs": []
762 | },
763 | {
764 | "cell_type": "markdown",
765 | "source": [
766 | "##Exemplo 10.8"
767 | ],
768 | "metadata": {
769 | "id": "f5viZKjR2Fjv"
770 | }
771 | },
772 | {
773 | "cell_type": "code",
774 | "source": [
775 | "# Exemplo 10.8\n",
776 | "# Servidor Yahoo está fora\n",
777 | "\n",
778 | "################################################################\n",
779 | "# #\n",
780 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
781 | "# pip install pandas_datareader #\n",
782 | "# #\n",
783 | "################################################################\n",
784 | "\n",
785 | "import datetime as dt\n",
786 | "import pandas_datareader.data as web\n",
787 | "import seaborn as sns\n",
788 | "\n",
789 | "inicio = dt.datetime(2019,1,1)\n",
790 | "fim = dt.datetime(2019,11,24)\n",
791 | "\n",
792 | "df1 = web.DataReader('^bvsp','yahoo',inicio,fim)\n",
793 | "df2 = web.DataReader('^dji','yahoo',inicio,fim)\n",
794 | "#+++++++++++++++++ Pareamento de datas para o mesmo dia +++++++++\n",
795 | "intersect = df2.index.intersection(df1.index)\n",
796 | "bov = df1.loc[intersect]\n",
797 | "dow = df2.loc[intersect]\n",
798 | "#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
799 | "retornoBV = bov['Close'].pct_change()\n",
800 | "retornoDJ = dow['Close'].pct_change()\n",
801 | "correlacao = retornoBV.corr(retornoDJ)\n",
802 | "\n",
803 | "dados = sns.regplot(bov['Close'],dow['Close'],color='black')\n",
804 | "\n",
805 | "dados.set_xlabel('IBOVESPA',fontsize=16)\n",
806 | "dados.set_ylabel('DOW JONES',fontsize=16)\n",
807 | "dados.set_title('Rgressão Linear Ibovespa x Dow Jones (Jan-Nov)/ 2019',\n",
808 | " fontsize=18)\n",
809 | "print('++++++++++++ Correção ++++++++++++')\n",
810 | "print(correlacao)"
811 | ],
812 | "metadata": {
813 | "id": "2GtKT21Z2GjL"
814 | },
815 | "execution_count": null,
816 | "outputs": []
817 | },
818 | {
819 | "cell_type": "markdown",
820 | "source": [
821 | "##Exemplo 10.9"
822 | ],
823 | "metadata": {
824 | "id": "9FrP55CV2L8t"
825 | }
826 | },
827 | {
828 | "cell_type": "code",
829 | "source": [
830 | "# Exemplo 10.9\n",
831 | "# Servidor Yahoo está fora\n",
832 | "\n",
833 | "################################################################\n",
834 | "# #\n",
835 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
836 | "# pip install pandas_datareader #\n",
837 | "# #\n",
838 | "################################################################\n",
839 | "\n",
840 | "import datetime as dt\n",
841 | "import pandas_datareader.data as web\n",
842 | "import seaborn as sns\n",
843 | "\n",
844 | "inicio = dt.datetime(2008,1,1)\n",
845 | "fim = dt.datetime(2019,11,24)\n",
846 | "\n",
847 | "df1 = web.DataReader('CL','yahoo',inicio,fim)\n",
848 | "df2 = web.DataReader('XOM','yahoo',inicio,fim)\n",
849 | "#+++++++++++++++++ Pareamento de datas para o mesmo dia +++++++++\n",
850 | "intersect = df2.index.intersection(df1.index)\n",
851 | "bov = df1.loc[intersect]\n",
852 | "dow = df2.loc[intersect]\n",
853 | "#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
854 | "retornoBV = bov['Close'].pct_change()\n",
855 | "retornoDJ = dow['Close'].pct_change()\n",
856 | "correlacao = retornoBV.corr(retornoDJ)\n",
857 | "\n",
858 | "dados = sns.regplot(bov['Close'],dow['Close'],color='black')\n",
859 | "\n",
860 | "dados.set_xlabel('IBOVESPA',fontsize=16)\n",
861 | "dados.set_ylabel('DOW JONES',fontsize=16)\n",
862 | "dados.set_title('Rgressão Linear Petróleo x EXXON 2008-2019',\n",
863 | " fontsize=18)\n",
864 | "print('++++++++++++ Correção ++++++++++++')\n",
865 | "print(correlacao)"
866 | ],
867 | "metadata": {
868 | "id": "FsShpDT-2M2H"
869 | },
870 | "execution_count": null,
871 | "outputs": []
872 | },
873 | {
874 | "cell_type": "markdown",
875 | "source": [
876 | "##Exemplo 10.10"
877 | ],
878 | "metadata": {
879 | "id": "I8aSWz9Y2TEC"
880 | }
881 | },
882 | {
883 | "cell_type": "code",
884 | "source": [
885 | "# Exemplo 10.10\n",
886 | "# Servidor Yahoo está fora\n",
887 | "\n",
888 | "################################################################\n",
889 | "# #\n",
890 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
891 | "# pip install pandas_datareader #\n",
892 | "# #\n",
893 | "################################################################\n",
894 | "\n",
895 | "# Explicação 1\n",
896 | "\n",
897 | "import matplotlib.pyplot as fig\n",
898 | "import datetime as dt\n",
899 | "import pandas_datareader.data as web\n",
900 | "\n",
901 | "inicio = dt.datetime(1995,1,1)\n",
902 | "fim = dt.datetime(2019,11,24)\n",
903 | "df = web.DataReader('^BVSP','yahoo',inicio,fim)\n",
904 | "df['Retorno'] = df['Close'].pct_change()\n",
905 | "df['Retorno'].plot(color='K',lw=2,alpha=0.4)\n",
906 | "df['std_mov'] = df['Retorno'].rolling(window=10,min_periods=0).std()\n",
907 | "df['std_mov'] .plot(color='k',lw=3,style='-')\n",
908 | "\n",
909 | "fig.grid()\n",
910 | "fig.title('Retorno financeiro Ibovespa (1995-2019)',fontsize=18,weight='bold')\n",
911 | "fig.legend(['Ibovespa','Volatilidade (desv.padrão) 10 dias'])"
912 | ],
913 | "metadata": {
914 | "id": "buIe8wN12UH_"
915 | },
916 | "execution_count": null,
917 | "outputs": []
918 | },
919 | {
920 | "cell_type": "code",
921 | "source": [
922 | "# Explicação 2\n",
923 | "\n",
924 | "################################################################\n",
925 | "# #\n",
926 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
927 | "# pip install pandas_datareader #\n",
928 | "# #\n",
929 | "################################################################\n",
930 | "\n",
931 | "import matplotlib.pyplot as fig\n",
932 | "import datetime as dt\n",
933 | "import pandas_datareader.data as web\n",
934 | "\n",
935 | "inicio = dt.datetime(1995,1,1)\n",
936 | "fim = dt.datetime(2019,11,24)\n",
937 | "df = web.DataReader('^BVSP','yahoo',inicio,fim)\n",
938 | "df['Retorno'] = df['Close'].pct_change()\n",
939 | "#df['Retorno'].plot(color='K',lw=2,alpha=0.4)\n",
940 | "df['med_mov'] = df['Close'].rolling(window=500,min_periods=0).mean()\n",
941 | "df['std_mov'] = df['Retorno'].rolling(window=10,min_periods=0).std()\n",
942 | "#df['std_mov'] .plot(color='k',lw=3,style='-')\n",
943 | "\n",
944 | "ax = fig.subplot(311)\n",
945 | "ax.plot(df.index,df['Close'],color='black',alpha=0.5)\n",
946 | "ax.plot(df.index,df['med_mov'],color='black')\n",
947 | "ax.set_title('Ibovespa (1995-2019)',fontsize=18,weight='bold')\n",
948 | "\n",
949 | "ax = fig.subplot(312)\n",
950 | "ax.plot(df.index,df['Retorno'],color='black',alpha=0.5)\n",
951 | "ax.plot(df.index,df['std_mov'],color='black')\n",
952 | "ax.set_title('Volatilidade retorno Ibovespa (1995-2019)',fontsize=18,weight='bold')\n",
953 | "fig.tight_layout()\n",
954 | "ax=fig.suplot(313)\n",
955 | "ax.bar(df.index,df['Volume'],color='black')\n",
956 | "ax.set_title('Volume Ibovespa (1995-2019)',fontsize=18,weight='bold')"
957 | ],
958 | "metadata": {
959 | "id": "Mvg6g0QD2ahm"
960 | },
961 | "execution_count": null,
962 | "outputs": []
963 | },
964 | {
965 | "cell_type": "markdown",
966 | "source": [
967 | "##Exemplo 10.11"
968 | ],
969 | "metadata": {
970 | "id": "hfx6Mv1m2fQk"
971 | }
972 | },
973 | {
974 | "cell_type": "code",
975 | "source": [
976 | "# Exemplo 10.11\n",
977 | "# Servidor Yahoo está fora\n",
978 | "\n",
979 | "################################################################\n",
980 | "# #\n",
981 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
982 | "# pip install pandas_datareader #\n",
983 | "# #\n",
984 | "################################################################\n",
985 | "\n",
986 | "import matplotlib.pyplot as fig\n",
987 | "import datetime as dt\n",
988 | "import pandas_datareader.data as web\n",
989 | "\n",
990 | "inicio = dt.datetime(1995,1,1)\n",
991 | "fim = dt.datetime(2019,11,24)\n",
992 | "df1 = web.DataReader('DGS10','fred',inicio,fim)\n",
993 | "df2 = web.DataReader('^DJI','yahoo',inicio,fim)\n",
994 | "df1['med_mov'] = df1['DGS10'].rolling(window=500,min_periods=0).mean()\n",
995 | "\n",
996 | "ax = fig.subplot(111)\n",
997 | "ax.plot(df1.index,df1['DGS10'],color='black',alpha=0.5)\n",
998 | "ax.plot(df1.index,df1['med_mov'],color='black')\n",
999 | "ax.set_title('Tesouro EUA - venc. 10 anos(10-year Treasury)',fontsize=14,weight='bold')\n",
1000 | "\n",
1001 | "ax2 = ax.twinx()\n",
1002 | "ax2.plot(df2.index,df2['Close'],color='black')\n",
1003 | "ax2.text(x=df1.index[11000],y=20000,s='DOW JONES',fontsize=14,weight='bold')\n",
1004 | "fig.grid()"
1005 | ],
1006 | "metadata": {
1007 | "id": "gIJ6dccd2gKx"
1008 | },
1009 | "execution_count": null,
1010 | "outputs": []
1011 | },
1012 | {
1013 | "cell_type": "markdown",
1014 | "source": [
1015 | "##Exemplo 10.12"
1016 | ],
1017 | "metadata": {
1018 | "id": "Hm71kyqH2kGT"
1019 | }
1020 | },
1021 | {
1022 | "cell_type": "code",
1023 | "source": [
1024 | "# Exemplo 10.12\n",
1025 | "# Servidor Yahoo está fora\n",
1026 | "\n",
1027 | "################################################################\n",
1028 | "# #\n",
1029 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
1030 | "# pip install pandas_datareader #\n",
1031 | "# #\n",
1032 | "################################################################\n",
1033 | "\n",
1034 | "import matplotlib.pyplot as fig\n",
1035 | "import datetime as dt\n",
1036 | "import pandas_datareader.data as web\n",
1037 | "import numpy as np\n",
1038 | "\n",
1039 | "inicio = dt.datetime(1970,1,1)\n",
1040 | "fim = dt.datetime(2019,11,24)\n",
1041 | "df1 = web.DataReader('DGS10','fred',inicio,fim)\n",
1042 | "df2 = web.DataReader('^DJI','yahoo',inicio,fim)\n",
1043 | "df1['Ret_Tit'] = df1['DGS10'].pct_change()\n",
1044 | "df2['Ret_Dow'] = df2['Close'].pct_change()\n",
1045 | "ax = fig.subplot(111)\n",
1046 | "ax.plot(df1.index,df1['Ret_Tit'],color='black',alpha=0.3)\n",
1047 | "ax.set_title('Retorno Tesouro EUA (10-year Treasury x Dow Jones)',fontsize=18,weight='bold')\n",
1048 | "ax.text(x=index[1000],y=0.05,s='Título de 10 anos',fontsize=14,weight='bold')\n",
1049 | "ax.plot(df2.tit.index,df2['Ret_Dow'],color='black')\n",
1050 | "ax.text(x=tit.index[5000],y=0.2,s='DOW JONES',fontsize=14,weight='bold')\n",
1051 | "fig.legend()\n",
1052 | "fig.grid()"
1053 | ],
1054 | "metadata": {
1055 | "id": "zkMQBrKu2k6P"
1056 | },
1057 | "execution_count": null,
1058 | "outputs": []
1059 | },
1060 | {
1061 | "cell_type": "markdown",
1062 | "source": [
1063 | "##Exemplo 10.13"
1064 | ],
1065 | "metadata": {
1066 | "id": "G_nJ9XmZ2qQD"
1067 | }
1068 | },
1069 | {
1070 | "cell_type": "code",
1071 | "source": [
1072 | "# Exemplo 10.13\n",
1073 | "# Servidor Yahoo está fora\n",
1074 | "\n",
1075 | "################################################################\n",
1076 | "# #\n",
1077 | "# ANTES DE RODAR A PRIMEIRA VEZ PRECISA INSTALAR A BIBLIOTECA #\n",
1078 | "# pip install pandas_datareader #\n",
1079 | "# #\n",
1080 | "################################################################\n",
1081 | "\n",
1082 | "import matplotlib.pyplot as fig\n",
1083 | "import datetime as dt\n",
1084 | "import pandas_datareader.data as web\n",
1085 | "import numpy as np\n",
1086 | "\n",
1087 | "inicio = dt.datetime(1970,1,1)\n",
1088 | "fim = dt.datetime(2019,11,24)\n",
1089 | "df1 = web.DataReader('DGS10','fred',inicio,fim)\n",
1090 | "df2 = web.DataReader('CL','yahoo',inicio,fim)\n",
1091 | "df1['Ret_Tit'] = df1['DGS10'].pct_change()\n",
1092 | "df2['Ret_oil'] = df2['Close'].pct_change()\n",
1093 | "ax = fig.subplot(111)\n",
1094 | "ax.plot(df1.index,df1['Ret_Tit'],color='black',alpha=0.3)\n",
1095 | "ax.set_title('Retorno Tesouro EUA (10-year Treasury x Dow Jones)',fontsize=18,weight='bold')\n",
1096 | "ax.text(x=index[1000],y=0.05,s='Título de 10 anos',fontsize=14,weight='bold')\n",
1097 | "ax.plot(df2.tit.index,df2['Ret_Dow'],color='black')\n",
1098 | "ax.text(x=tit.index[5000],y=0.2,s='DOW JONES',fontsize=14,weight='bold')\n",
1099 | "fig.legend()\n",
1100 | "fig.grid()"
1101 | ],
1102 | "metadata": {
1103 | "id": "daV9hHi12rM0"
1104 | },
1105 | "execution_count": null,
1106 | "outputs": []
1107 | }
1108 | ]
1109 | }
--------------------------------------------------------------------------------
/CAPÍTULO_2_ITERAÇÃO_E_DECISÃO.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "toc_visible": true,
8 | "authorship_tag": "ABX9TyO6qtEMGAmX7vpZhxMzGhb1",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | },
15 | "language_info": {
16 | "name": "python"
17 | }
18 | },
19 | "cells": [
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {
23 | "id": "view-in-github",
24 | "colab_type": "text"
25 | },
26 | "source": [
27 | "
"
28 | ]
29 | },
30 | {
31 | "cell_type": "markdown",
32 | "source": [
33 | "#CAPÍTULO 2 - ITERAÇÃO E DECISÃO"
34 | ],
35 | "metadata": {
36 | "id": "fGAl0JpSBTlE"
37 | }
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "source": [
42 | "#Exemplos"
43 | ],
44 | "metadata": {
45 | "id": "JepO346vVgfD"
46 | }
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "source": [
51 | "##Exemplo 2.1"
52 | ],
53 | "metadata": {
54 | "id": "Qa37WLVn9OLQ"
55 | }
56 | },
57 | {
58 | "cell_type": "code",
59 | "source": [
60 | "# Exemplo 2.1\n",
61 | "# Cálculo da área de círculo\n",
62 | "\n",
63 | "import math\n",
64 | "\n",
65 | "raio = float(input(\"Raio = \"))\n",
66 | "area = math.pi * raio**2\n",
67 | "print(\"Área = \", area)"
68 | ],
69 | "metadata": {
70 | "colab": {
71 | "base_uri": "https://localhost:8080/"
72 | },
73 | "id": "77KSi2ZfCKHD",
74 | "outputId": "cb9054b5-e306-4c8b-ac0e-315c608f4ecc"
75 | },
76 | "execution_count": 2,
77 | "outputs": [
78 | {
79 | "output_type": "stream",
80 | "name": "stdout",
81 | "text": [
82 | "Raio = 3.5\n",
83 | "Área = 38.48451000647496\n"
84 | ]
85 | }
86 | ]
87 | },
88 | {
89 | "cell_type": "markdown",
90 | "source": [
91 | "##Exemplo 2.2"
92 | ],
93 | "metadata": {
94 | "id": "VPooa0P-CeCj"
95 | }
96 | },
97 | {
98 | "cell_type": "code",
99 | "source": [
100 | "# Exemplo 2.2\n",
101 | "\n",
102 | "import math\n",
103 | "\n",
104 | "x = float(input(\"X = \"))\n",
105 | "y = float(input(\"Y = \"))\n",
106 | "z = math.sqrt(x**2 + y) - math.log(x) + math.exp(y)\n",
107 | "\n",
108 | "print(\"Valor de z = \", z)"
109 | ],
110 | "metadata": {
111 | "colab": {
112 | "base_uri": "https://localhost:8080/"
113 | },
114 | "id": "6BtKq-sbCKu1",
115 | "outputId": "be5f800b-27ee-4dd0-c332-d6dacc194d47"
116 | },
117 | "execution_count": 3,
118 | "outputs": [
119 | {
120 | "output_type": "stream",
121 | "name": "stdout",
122 | "text": [
123 | "X = 2\n",
124 | "Y = 3\n",
125 | "Valor de z = 22.038141053692314\n"
126 | ]
127 | }
128 | ]
129 | },
130 | {
131 | "cell_type": "markdown",
132 | "source": [
133 | "##Exemplo 2.3"
134 | ],
135 | "metadata": {
136 | "id": "vXnXeQlpCw3k"
137 | }
138 | },
139 | {
140 | "cell_type": "code",
141 | "source": [
142 | "# Exemplo 2.3\n",
143 | "\n",
144 | "r1 = float(input(\"Retorno 1 = \"))\n",
145 | "r2 = float(input(\"Retorno 2 = \"))\n",
146 | "r3 = float(input(\"Retorno 3 = \"))\n",
147 | "\n",
148 | "p1 = float(input(\"Probabilidade 1 = \"))\n",
149 | "p2 = float(input(\"Probabilidade 2 = \"))\n",
150 | "p3 = float(input(\"Probabilidade 3 = \"))\n",
151 | "\n",
152 | "ret_medio = r1 * p1 + r2 * p2 + r3 * p3\n",
153 | "\n",
154 | "print(\"Retorno média = \", ret_medio)"
155 | ],
156 | "metadata": {
157 | "colab": {
158 | "base_uri": "https://localhost:8080/"
159 | },
160 | "id": "hNYpXCSHCynJ",
161 | "outputId": "be2ed36e-ba6d-4fe7-e8ff-78c57e3130c1"
162 | },
163 | "execution_count": 4,
164 | "outputs": [
165 | {
166 | "output_type": "stream",
167 | "name": "stdout",
168 | "text": [
169 | "Retorno 1 = 100\n",
170 | "Retorno 2 = 90\n",
171 | "Retorno 3 = 120\n",
172 | "Probabilidade 1 = 0.2\n",
173 | "Probabilidade 2 = 0.7\n",
174 | "Probabilidade 3 = 0.1\n",
175 | "Retorno média = 95.0\n"
176 | ]
177 | }
178 | ]
179 | },
180 | {
181 | "cell_type": "markdown",
182 | "source": [
183 | "##Exemplo 2.4"
184 | ],
185 | "metadata": {
186 | "id": "GldbNZBxDSLX"
187 | }
188 | },
189 | {
190 | "cell_type": "code",
191 | "source": [
192 | "# Exemplo 2.4\n",
193 | "# Calculo retorno\n",
194 | "\n",
195 | "p1 = float(input(\"Resultado do primeiro dia = \"))\n",
196 | "p2 = float(input(\"Resultado do segundo dia = \"))\n",
197 | "retorno = p2 - p1\n",
198 | "if retorno >= 0:\n",
199 | " print(\"lucro\")\n",
200 | " print(\"fiquei feliz\")\n",
201 | "else:\n",
202 | " print(\"prejuizo\")\n",
203 | " print(\"fiquei triste\")"
204 | ],
205 | "metadata": {
206 | "colab": {
207 | "base_uri": "https://localhost:8080/"
208 | },
209 | "id": "42GoURoGDUK7",
210 | "outputId": "991f24de-387c-426a-d4e1-a9c36b15c7cf"
211 | },
212 | "execution_count": 5,
213 | "outputs": [
214 | {
215 | "output_type": "stream",
216 | "name": "stdout",
217 | "text": [
218 | "Resultado do primeiro dia = 10\n",
219 | "Resultado do segundo dia = 20\n",
220 | "lucro\n",
221 | "fiquei feliz\n"
222 | ]
223 | }
224 | ]
225 | },
226 | {
227 | "cell_type": "code",
228 | "source": [
229 | "#Código com erro identação\n",
230 | "\n",
231 | "p1 = float(input(\"Resultado do primeiro dia = \"))\n",
232 | "p2 = float(input(\"Resultado do segundo dia = \"))\n",
233 | "retorno = p2 - p1\n",
234 | "if retorno >= 0:\n",
235 | " print(\"lucro\")\n",
236 | " print(\"fiquei feliz\")\n",
237 | "else:\n",
238 | " print(\"prejuizo\")\n",
239 | "print(\"fiquei triste\")"
240 | ],
241 | "metadata": {
242 | "colab": {
243 | "base_uri": "https://localhost:8080/"
244 | },
245 | "id": "w2ARdibJDezk",
246 | "outputId": "f3d84c0b-8893-43f0-9d9c-72af04b487cc"
247 | },
248 | "execution_count": 6,
249 | "outputs": [
250 | {
251 | "output_type": "stream",
252 | "name": "stdout",
253 | "text": [
254 | "Resultado do primeiro dia = 10\n",
255 | "Resultado do segundo dia = 20\n",
256 | "lucro\n",
257 | "fiquei feliz\n",
258 | "fiquei triste\n"
259 | ]
260 | }
261 | ]
262 | },
263 | {
264 | "cell_type": "markdown",
265 | "source": [
266 | "##Exemplo 2.5"
267 | ],
268 | "metadata": {
269 | "id": "vuuMQKYlD16q"
270 | }
271 | },
272 | {
273 | "cell_type": "code",
274 | "source": [
275 | "# Exemplo 2.5\n",
276 | "# Calculo faixa de preço\n",
277 | "\n",
278 | "p1 = float(input(\"preço 1 = \"))\n",
279 | "\n",
280 | "if p1 <= 18:\n",
281 | " print(\"barato\")\n",
282 | "elif (p1 > 18) and (p1 <= 25):\n",
283 | " print(\"adequado\")\n",
284 | "elif (p1 > 25) and (p1 <= 32):\n",
285 | " print(\"caro\")\n",
286 | "else:\n",
287 | " print(\"extremamente caro\")"
288 | ],
289 | "metadata": {
290 | "colab": {
291 | "base_uri": "https://localhost:8080/"
292 | },
293 | "id": "9ruMC_l3D4bY",
294 | "outputId": "b4e1323b-4323-459e-cd7e-0822e2c7806b"
295 | },
296 | "execution_count": 7,
297 | "outputs": [
298 | {
299 | "output_type": "stream",
300 | "name": "stdout",
301 | "text": [
302 | "preço 1 = 30\n",
303 | "caro\n"
304 | ]
305 | }
306 | ]
307 | },
308 | {
309 | "cell_type": "markdown",
310 | "source": [
311 | "##Exemplo 2.6"
312 | ],
313 | "metadata": {
314 | "id": "YiktfCOdEEVi"
315 | }
316 | },
317 | {
318 | "cell_type": "code",
319 | "source": [
320 | "# Exemplo 2.6\n",
321 | "# Decide se um número é par ou impar\n",
322 | "\n",
323 | "n = int(input(\"Entre com um número = \"))\n",
324 | "\n",
325 | "resto = n % 2\n",
326 | "if (resto == 0):\n",
327 | " print(\"Par\")\n",
328 | "else:\n",
329 | " print(\"Impar\")"
330 | ],
331 | "metadata": {
332 | "colab": {
333 | "base_uri": "https://localhost:8080/"
334 | },
335 | "id": "hUwSBt0YEGfY",
336 | "outputId": "8cd49ce3-5363-4c75-d724-bedcc91dce02"
337 | },
338 | "execution_count": 8,
339 | "outputs": [
340 | {
341 | "output_type": "stream",
342 | "name": "stdout",
343 | "text": [
344 | "Entre com um número = 113\n",
345 | "Impar\n"
346 | ]
347 | }
348 | ]
349 | },
350 | {
351 | "cell_type": "markdown",
352 | "source": [
353 | "##Exemplo 2.7"
354 | ],
355 | "metadata": {
356 | "id": "PxFFpoGhEQ1a"
357 | }
358 | },
359 | {
360 | "cell_type": "code",
361 | "source": [
362 | "# Exemplo 2.7\n",
363 | "# Encadeamento de If\n",
364 | "\n",
365 | "perg1 = str(input(\"Temer sai? \"))\n",
366 | "if perg1 == 's':\n",
367 | " perg2 = str(input(\"Maia assume a presidencia? \"))\n",
368 | " if perg2 == 's':\n",
369 | " perg3 = str(input(\"Antecipa a eleição? \"))\n",
370 | " if perg3 == 's':\n",
371 | " print(\"Comprar Petrobras.\")\n",
372 | " else:\n",
373 | " print(\"Comprar Usiminas.\")\n",
374 | " else:\n",
375 | " perg3 = str(input(\"Antecipa a eleição? \"))\n",
376 | " if perg3 == 's':\n",
377 | " print(\"Comprar Gerdau.\")\n",
378 | " else:\n",
379 | " print(\"Comprar Vale.\")\n",
380 | "else:\n",
381 | " perg2 = str(input(\"Greve dos caminhoneiros? \"))\n",
382 | " if perg2 == 's':\n",
383 | " print(\"Comprar dólar.\")\n",
384 | " else:\n",
385 | " print(\"Comprar ouro.\")"
386 | ],
387 | "metadata": {
388 | "colab": {
389 | "base_uri": "https://localhost:8080/"
390 | },
391 | "id": "RxNPGgfuEO8J",
392 | "outputId": "869c7a72-53bb-42d9-9e13-7a7a71e3dbd6"
393 | },
394 | "execution_count": 10,
395 | "outputs": [
396 | {
397 | "output_type": "stream",
398 | "name": "stdout",
399 | "text": [
400 | "Temer sai? s\n",
401 | "Maia assume a presidencia? s\n",
402 | "Antecipa a eleição? n\n",
403 | "Comprar Usiminas.\n"
404 | ]
405 | }
406 | ]
407 | },
408 | {
409 | "cell_type": "markdown",
410 | "source": [
411 | "##Exemplo 2.8"
412 | ],
413 | "metadata": {
414 | "id": "9pSkjGc1EktH"
415 | }
416 | },
417 | {
418 | "cell_type": "code",
419 | "source": [
420 | "# Exemplo 2.8\n",
421 | "\n",
422 | "cont = 1\n",
423 | "x = 0\n",
424 | "while x < 20:\n",
425 | " x = cont * 5\n",
426 | " cont = cont +1\n",
427 | " print(x)"
428 | ],
429 | "metadata": {
430 | "colab": {
431 | "base_uri": "https://localhost:8080/"
432 | },
433 | "id": "F8CBarjxEmLK",
434 | "outputId": "c2b176bd-b5c6-4d6b-a093-8bf8bcf1b84f"
435 | },
436 | "execution_count": 11,
437 | "outputs": [
438 | {
439 | "output_type": "stream",
440 | "name": "stdout",
441 | "text": [
442 | "5\n",
443 | "10\n",
444 | "15\n",
445 | "20\n"
446 | ]
447 | }
448 | ]
449 | },
450 | {
451 | "cell_type": "markdown",
452 | "source": [
453 | "##Exemplo 2.9"
454 | ],
455 | "metadata": {
456 | "id": "ikP4OPLtE1Mv"
457 | }
458 | },
459 | {
460 | "cell_type": "code",
461 | "source": [
462 | "# Exemplo 2.9\n",
463 | "# Soma de n números pares\n",
464 | "\n",
465 | "n = int(input(\"Quantidade de números = \"))\n",
466 | "cont = 0\n",
467 | "s = 0\n",
468 | "while cont <= n:\n",
469 | " if cont % 2 == 0:\n",
470 | " s = s + cont\n",
471 | " print(s)\n",
472 | " cont = cont + 1"
473 | ],
474 | "metadata": {
475 | "colab": {
476 | "base_uri": "https://localhost:8080/"
477 | },
478 | "id": "Hi0sY4j9E2az",
479 | "outputId": "3e94306f-62dc-4b95-d063-628a73e70f0b"
480 | },
481 | "execution_count": 12,
482 | "outputs": [
483 | {
484 | "output_type": "stream",
485 | "name": "stdout",
486 | "text": [
487 | "Quantidade de números = 10\n",
488 | "0\n",
489 | "2\n",
490 | "6\n",
491 | "12\n",
492 | "20\n",
493 | "30\n"
494 | ]
495 | }
496 | ]
497 | },
498 | {
499 | "cell_type": "markdown",
500 | "source": [
501 | "##Exemplo 2.10"
502 | ],
503 | "metadata": {
504 | "id": "b0GDWVhCFHUD"
505 | }
506 | },
507 | {
508 | "cell_type": "code",
509 | "source": [
510 | "# Exemplo 2.10\n",
511 | "# Imprimir parte de uma lista\n",
512 | "\n",
513 | "nomes = ['mário','josé','mário','maria','carlos','ana','mário']\n",
514 | "n = len(nomes)\n",
515 | "cont = 1\n",
516 | "\n",
517 | "while cont <= n-1:\n",
518 | " if nomes[cont] != 'mário':\n",
519 | " print(nomes[cont])\n",
520 | " cont = cont + 1"
521 | ],
522 | "metadata": {
523 | "colab": {
524 | "base_uri": "https://localhost:8080/"
525 | },
526 | "id": "ZgKmHiapFIYW",
527 | "outputId": "f134d505-eaf4-4215-8adb-064f82adb38f"
528 | },
529 | "execution_count": 13,
530 | "outputs": [
531 | {
532 | "output_type": "stream",
533 | "name": "stdout",
534 | "text": [
535 | "josé\n",
536 | "maria\n",
537 | "carlos\n",
538 | "ana\n"
539 | ]
540 | }
541 | ]
542 | },
543 | {
544 | "cell_type": "markdown",
545 | "source": [
546 | "##Exemplo 2.11"
547 | ],
548 | "metadata": {
549 | "id": "-_8fPJWdFifU"
550 | }
551 | },
552 | {
553 | "cell_type": "code",
554 | "source": [
555 | "# Exemplo 2.11\n",
556 | "# Soma de n números\n",
557 | "\n",
558 | "n = int(input(\"Quantidade de números = \"))\n",
559 | "cont = 1\n",
560 | "s = 0\n",
561 | "while cont <= n:\n",
562 | " s = s + cont\n",
563 | " if s % 2 == 0 : break\n",
564 | " cont = cont + 1\n",
565 | " print(s)"
566 | ],
567 | "metadata": {
568 | "colab": {
569 | "base_uri": "https://localhost:8080/"
570 | },
571 | "id": "1IehIjMDFM_q",
572 | "outputId": "fefdf052-84df-4965-a313-cda7300c27ac"
573 | },
574 | "execution_count": 14,
575 | "outputs": [
576 | {
577 | "output_type": "stream",
578 | "name": "stdout",
579 | "text": [
580 | "Quantidade de números = 10\n",
581 | "1\n",
582 | "3\n"
583 | ]
584 | }
585 | ]
586 | },
587 | {
588 | "cell_type": "markdown",
589 | "source": [
590 | "##Exemplo 2.12"
591 | ],
592 | "metadata": {
593 | "id": "2jF501pmFhwL"
594 | }
595 | },
596 | {
597 | "cell_type": "code",
598 | "source": [
599 | "# Exemplo 2.12\n",
600 | "# Soma de n números\n",
601 | "\n",
602 | "n = int(input(\"Quantidade de números = \"))\n",
603 | "cont = 1\n",
604 | "s = 0\n",
605 | "while cont <= n:\n",
606 | " s = s + cont\n",
607 | " if s % 2 == 0 : continue\n",
608 | " cont = cont + 1\n",
609 | " print(s)"
610 | ],
611 | "metadata": {
612 | "colab": {
613 | "base_uri": "https://localhost:8080/"
614 | },
615 | "id": "zFLwpN-_FoIN",
616 | "outputId": "e9a2adb5-b3b5-483a-8370-cf1f058662a3"
617 | },
618 | "execution_count": 15,
619 | "outputs": [
620 | {
621 | "output_type": "stream",
622 | "name": "stdout",
623 | "text": [
624 | "Quantidade de números = 10\n",
625 | "1\n",
626 | "3\n",
627 | "9\n",
628 | "13\n",
629 | "23\n",
630 | "29\n",
631 | "43\n",
632 | "51\n",
633 | "69\n",
634 | "79\n"
635 | ]
636 | }
637 | ]
638 | },
639 | {
640 | "cell_type": "markdown",
641 | "source": [
642 | "##Exemplo 2.13"
643 | ],
644 | "metadata": {
645 | "id": "XT7D5ne8GJmb"
646 | }
647 | },
648 | {
649 | "cell_type": "code",
650 | "source": [
651 | "# Exemplo 2.13\n",
652 | "# Imprimindo\n",
653 | "\n",
654 | "n = int(input(\"Total de números = \"))\n",
655 | "s = 0\n",
656 | "\n",
657 | "for i in range(0, n):\n",
658 | " x = float(input(\"Número = \"))\n",
659 | " s = s + x\n",
660 | " print(s)\n",
661 | "print(\"Soma total = \", s)"
662 | ],
663 | "metadata": {
664 | "colab": {
665 | "base_uri": "https://localhost:8080/"
666 | },
667 | "id": "A3W0B4UXGLfH",
668 | "outputId": "22f052a5-7b0d-4a2c-925f-f26ca5aed185"
669 | },
670 | "execution_count": 17,
671 | "outputs": [
672 | {
673 | "output_type": "stream",
674 | "name": "stdout",
675 | "text": [
676 | "Total de números = 5\n",
677 | "Número = -2\n",
678 | "-2.0\n",
679 | "Número = 4\n",
680 | "2.0\n",
681 | "Número = 5\n",
682 | "7.0\n",
683 | "Número = 7\n",
684 | "14.0\n",
685 | "Número = -1\n",
686 | "13.0\n",
687 | "Soma total = 13.0\n"
688 | ]
689 | }
690 | ]
691 | },
692 | {
693 | "cell_type": "markdown",
694 | "source": [
695 | "##Exemplo 2.14"
696 | ],
697 | "metadata": {
698 | "id": "xeCRs4cZGj4Q"
699 | }
700 | },
701 | {
702 | "cell_type": "code",
703 | "source": [
704 | "# Exemplo 2.14\n",
705 | "# Imprimindo palavras\n",
706 | "\n",
707 | "lista_nomes = ['um', 'dois', 'três', 'quatro','cinco']\n",
708 | "nova = []\n",
709 | "for i in range(len(lista_nomes)-1 ,-1,-1):\n",
710 | " nova.append(lista_nomes[i-len(lista_nomes)])\n",
711 | "print(nova)"
712 | ],
713 | "metadata": {
714 | "colab": {
715 | "base_uri": "https://localhost:8080/"
716 | },
717 | "id": "yHjPpTXVGVik",
718 | "outputId": "ba994f37-daf6-44c6-92bb-3f614969495a"
719 | },
720 | "execution_count": 18,
721 | "outputs": [
722 | {
723 | "output_type": "stream",
724 | "name": "stdout",
725 | "text": [
726 | "['cinco', 'quatro', 'três', 'dois', 'um']\n"
727 | ]
728 | }
729 | ]
730 | },
731 | {
732 | "cell_type": "markdown",
733 | "source": [
734 | "##Exemplo 2.15"
735 | ],
736 | "metadata": {
737 | "id": "g7cjTfxOGrin"
738 | }
739 | },
740 | {
741 | "cell_type": "code",
742 | "source": [
743 | "# Exemplo 2.15\n",
744 | "# Exemplo para fatiar uma lista com for\n",
745 | "\n",
746 | "letras = [['a','b','c'],['a','d','f','a'],['b','b','d','c']]\n",
747 | "i = 1 # Pra que?\n",
748 | "letras_novas = []\n",
749 | "for p in letras:\n",
750 | " for x in p:\n",
751 | " letras_novas.append(x)\n",
752 | "\n",
753 | "print('++++++++ Nova Lista ++++++++')\n",
754 | "print(letras_novas)"
755 | ],
756 | "metadata": {
757 | "colab": {
758 | "base_uri": "https://localhost:8080/"
759 | },
760 | "id": "DjD5oOStGoqk",
761 | "outputId": "690a9714-3d20-4abe-a1b3-25bc0be5d4cc"
762 | },
763 | "execution_count": 19,
764 | "outputs": [
765 | {
766 | "output_type": "stream",
767 | "name": "stdout",
768 | "text": [
769 | "++++++++ Nova Lista ++++++++\n",
770 | "['a', 'b', 'c', 'a', 'd', 'f', 'a', 'b', 'b', 'd', 'c']\n"
771 | ]
772 | }
773 | ]
774 | },
775 | {
776 | "cell_type": "markdown",
777 | "source": [
778 | "##Exemplo 2.16"
779 | ],
780 | "metadata": {
781 | "id": "Fr_TGcAdGxrA"
782 | }
783 | },
784 | {
785 | "cell_type": "code",
786 | "source": [
787 | "# Exemplo 2.16\n",
788 | "# Fatorial\n",
789 | "\n",
790 | "n = int(input(\"n = \"))\n",
791 | "fat = 1\n",
792 | "for i in range(1, n+1):\n",
793 | " fat = fat * i\n",
794 | "print(\"Fatorial = \", fat)"
795 | ],
796 | "metadata": {
797 | "colab": {
798 | "base_uri": "https://localhost:8080/"
799 | },
800 | "id": "iJ84RIWOGwTw",
801 | "outputId": "3f6de9ed-2efe-483a-8e26-0a9342632098"
802 | },
803 | "execution_count": 20,
804 | "outputs": [
805 | {
806 | "output_type": "stream",
807 | "name": "stdout",
808 | "text": [
809 | "n = 3\n",
810 | "Fatorial = 6\n"
811 | ]
812 | }
813 | ]
814 | },
815 | {
816 | "cell_type": "code",
817 | "source": [
818 | "import math\n",
819 | "n = int(input(\"n = \"))\n",
820 | "fat = math.factorial(n)\n",
821 | "print(\"Fatorial com a biblioteca math = \", fat)"
822 | ],
823 | "metadata": {
824 | "colab": {
825 | "base_uri": "https://localhost:8080/"
826 | },
827 | "id": "k0djDC2KG3AU",
828 | "outputId": "ccd2228c-f2de-4e92-9ac0-ed359638c8b3"
829 | },
830 | "execution_count": 21,
831 | "outputs": [
832 | {
833 | "output_type": "stream",
834 | "name": "stdout",
835 | "text": [
836 | "n = 3\n",
837 | "Fatorial com a biblioteca math = 6\n"
838 | ]
839 | }
840 | ]
841 | },
842 | {
843 | "cell_type": "markdown",
844 | "source": [
845 | "##Exemplo 2.17"
846 | ],
847 | "metadata": {
848 | "id": "rAMuyI_AHB_Z"
849 | }
850 | },
851 | {
852 | "cell_type": "code",
853 | "source": [
854 | "# Exemplo 2.17\n",
855 | "# Algoritmo do Exponencial\n",
856 | "\n",
857 | "n = int(input(\"n = \"))\n",
858 | "x = float(input(\"x = \"))\n",
859 | "fat = 1\n",
860 | "s = 1\n",
861 | "for i in range(1, n + 1):\n",
862 | " fat = fat * i\n",
863 | " s = s + x**i/fat\n",
864 | "print(\"Soma = \", s)"
865 | ],
866 | "metadata": {
867 | "colab": {
868 | "base_uri": "https://localhost:8080/"
869 | },
870 | "id": "Z4-f-DWtG9ie",
871 | "outputId": "edcffc4d-a5e9-4826-d47c-9383e95a102c"
872 | },
873 | "execution_count": 23,
874 | "outputs": [
875 | {
876 | "output_type": "stream",
877 | "name": "stdout",
878 | "text": [
879 | "n = 10\n",
880 | "x = 1\n",
881 | "Soma = 2.7182818011463845\n"
882 | ]
883 | }
884 | ]
885 | },
886 | {
887 | "cell_type": "code",
888 | "source": [
889 | "import math\n",
890 | "n = int(input(\"n = \"))\n",
891 | "s = math.exp(n)\n",
892 | "print(\"Soma = \",s)"
893 | ],
894 | "metadata": {
895 | "colab": {
896 | "base_uri": "https://localhost:8080/"
897 | },
898 | "id": "SG8Ng2OrHQvp",
899 | "outputId": "13fee0f4-1c56-4a79-8b77-475b6b187817"
900 | },
901 | "execution_count": 25,
902 | "outputs": [
903 | {
904 | "output_type": "stream",
905 | "name": "stdout",
906 | "text": [
907 | "n = 1\n",
908 | "Soma = 2.718281828459045\n"
909 | ]
910 | }
911 | ]
912 | },
913 | {
914 | "cell_type": "markdown",
915 | "source": [
916 | "#Exercícios 2.9\n"
917 | ],
918 | "metadata": {
919 | "id": "puuN8Jyn-hwR"
920 | }
921 | },
922 | {
923 | "cell_type": "markdown",
924 | "source": [
925 | "##Exercício 1"
926 | ],
927 | "metadata": {
928 | "id": "17m8sc9A_gyx"
929 | }
930 | },
931 | {
932 | "cell_type": "code",
933 | "source": [
934 | "# Exercícios 2.9\n",
935 | "# 1\n",
936 | "# Solução do autor\n",
937 | "\n",
938 | "n =int(input(\"n = \"))\n",
939 | "if n >= 0:\n",
940 | " print(\"Positivo\")\n",
941 | "else:\n",
942 | " print(\"Negativo\")"
943 | ],
944 | "metadata": {
945 | "colab": {
946 | "base_uri": "https://localhost:8080/"
947 | },
948 | "id": "k0ot0Gk8Pjfu",
949 | "outputId": "1aae3996-8b9d-4279-b25e-c27ee9f7d5fa"
950 | },
951 | "execution_count": 26,
952 | "outputs": [
953 | {
954 | "output_type": "stream",
955 | "name": "stdout",
956 | "text": [
957 | "n = 10\n",
958 | "Positivo\n"
959 | ]
960 | }
961 | ]
962 | },
963 | {
964 | "cell_type": "code",
965 | "source": [
966 | "# Minha solução\n",
967 | "\n",
968 | "n = float(input(\"Digite um número: \"))\n",
969 | "\n",
970 | "if n > 0:\n",
971 | " print(\"O número \", n ,\" é positivo.\")\n",
972 | "elif n < 0:\n",
973 | " print(\"O número \", n ,\" é negativo.\")\n",
974 | "else:\n",
975 | " print(\"O número \", n ,\" é zero.\")"
976 | ],
977 | "metadata": {
978 | "colab": {
979 | "base_uri": "https://localhost:8080/"
980 | },
981 | "id": "f_jN7icUPvnZ",
982 | "outputId": "a5418cb2-1e5a-4719-da34-5edc800dfc96"
983 | },
984 | "execution_count": 27,
985 | "outputs": [
986 | {
987 | "output_type": "stream",
988 | "name": "stdout",
989 | "text": [
990 | "Digite um número: 10\n",
991 | "O número 10.0 é positivo.\n"
992 | ]
993 | }
994 | ]
995 | },
996 | {
997 | "cell_type": "markdown",
998 | "source": [
999 | "##Exercício 2"
1000 | ],
1001 | "metadata": {
1002 | "id": "8o1EJSHAS9AP"
1003 | }
1004 | },
1005 | {
1006 | "cell_type": "code",
1007 | "source": [
1008 | "# Exercícios 2.9\n",
1009 | "# 2\n",
1010 | "# Solução do autor\n",
1011 | "\n",
1012 | "ld1 = float(input(\"Lado 1 = \"))\n",
1013 | "ld2 = float(input(\"Lado 2 = \"))\n",
1014 | "ld3 = float(input(\"Lado 3 = \"))\n",
1015 | "if (ld1 != ld2) and (ld1 != ld3) and (ld2 != ld3):\n",
1016 | " print(\"Escaleno\")\n",
1017 | "elif (ld1 == ld2) and (ld1 == ld3) and (ld2 == ld3):\n",
1018 | " print(\"Equilátero\")\n",
1019 | "else:\n",
1020 | " print(\"Isósceles\")"
1021 | ],
1022 | "metadata": {
1023 | "colab": {
1024 | "base_uri": "https://localhost:8080/"
1025 | },
1026 | "id": "h0_u3OTGS-sA",
1027 | "outputId": "7676818e-f035-4fe5-a74e-d09512474225"
1028 | },
1029 | "execution_count": 28,
1030 | "outputs": [
1031 | {
1032 | "output_type": "stream",
1033 | "name": "stdout",
1034 | "text": [
1035 | "Lado 1 = 1\n",
1036 | "Lado 2 = 5\n",
1037 | "Lado 3 = 7\n",
1038 | "Escaleno\n"
1039 | ]
1040 | }
1041 | ]
1042 | },
1043 | {
1044 | "cell_type": "code",
1045 | "source": [
1046 | "#Minha solução\n",
1047 | "\n",
1048 | "a = int(input(\"Digite o tamanho do lado A: \"))\n",
1049 | "b = int(input(\"Digite o tamanho do lado B: \"))\n",
1050 | "c = int(input(\"Digite o tamanho do lado C: \"))\n",
1051 | "\n",
1052 | "if a == b and b == c:\n",
1053 | " print(\"Tiângulo Equilátero\")\n",
1054 | "\n",
1055 | "elif a == b or b == c or a == c:\n",
1056 | " print(\"Tiângulo Isósceles\")\n",
1057 | "\n",
1058 | "else:\n",
1059 | " print(\"Triângulo Escaleno\")"
1060 | ],
1061 | "metadata": {
1062 | "colab": {
1063 | "base_uri": "https://localhost:8080/"
1064 | },
1065 | "id": "eMl3X99eTQQ1",
1066 | "outputId": "715e48d5-9952-431a-f815-f09408a5ee85"
1067 | },
1068 | "execution_count": 29,
1069 | "outputs": [
1070 | {
1071 | "output_type": "stream",
1072 | "name": "stdout",
1073 | "text": [
1074 | "Digite o tamanho do lado A: 1\n",
1075 | "Digite o tamanho do lado B: 5\n",
1076 | "Digite o tamanho do lado C: 7\n",
1077 | "Triângulo Escaleno\n"
1078 | ]
1079 | }
1080 | ]
1081 | },
1082 | {
1083 | "cell_type": "markdown",
1084 | "source": [
1085 | "##Exercício 3"
1086 | ],
1087 | "metadata": {
1088 | "id": "GK_h6JnyTtRh"
1089 | }
1090 | },
1091 | {
1092 | "cell_type": "code",
1093 | "source": [
1094 | "# Exercícios 2.9\n",
1095 | "# 3\n",
1096 | "# Solução do autor\n",
1097 | "\n",
1098 | "compra = float(input(\"Preço de compra = \"))\n",
1099 | "venda = float(input(\"Preço de venda = \"))\n",
1100 | "\n",
1101 | "retorno = venda - compra\n",
1102 | "faixa = retorno / compra\n",
1103 | "\n",
1104 | "if faixa < 0.1:\n",
1105 | " print(\"Lucro abaixo de 10%\")\n",
1106 | "elif faixa <= 0.2:\n",
1107 | " print(\"Lucro entre 10% e 20%\")\n",
1108 | "else:\n",
1109 | " print(\"Lucro acima de 20%\")"
1110 | ],
1111 | "metadata": {
1112 | "colab": {
1113 | "base_uri": "https://localhost:8080/"
1114 | },
1115 | "id": "Wet12yjhTk2p",
1116 | "outputId": "8f6dd35b-0316-43b7-bf74-ce03a01b845c"
1117 | },
1118 | "execution_count": 30,
1119 | "outputs": [
1120 | {
1121 | "output_type": "stream",
1122 | "name": "stdout",
1123 | "text": [
1124 | "Preço de compra = 30\n",
1125 | "Preço de venda = 50\n",
1126 | "Lucro acima de 20%\n"
1127 | ]
1128 | }
1129 | ]
1130 | },
1131 | {
1132 | "cell_type": "code",
1133 | "source": [
1134 | "#Minha solução\n",
1135 | "\n",
1136 | "a = int(input(\"Digite o preço de compra: \"))\n",
1137 | "b = int(input(\"Digite o preço de venda: \"))\n",
1138 | "\n",
1139 | "c = ((b - a) / a) * 100\n",
1140 | "\n",
1141 | "if c > 0 and c < 10:\n",
1142 | " print(\"Lucro é menor que 10%.\")\n",
1143 | "\n",
1144 | "elif c > 10 and c <= 20:\n",
1145 | " print(\"Lucro é maior que 10%.\")\n",
1146 | "\n",
1147 | "elif c > 20:\n",
1148 | " print(\"Lucro é maior que 20%.\")\n",
1149 | "\n",
1150 | "else:\n",
1151 | " print(\"Venda deu prejuizo.\")"
1152 | ],
1153 | "metadata": {
1154 | "colab": {
1155 | "base_uri": "https://localhost:8080/"
1156 | },
1157 | "id": "lJWcx_xXTyeg",
1158 | "outputId": "c319bc13-c5e9-4116-9932-2686c9bfe6b1"
1159 | },
1160 | "execution_count": 31,
1161 | "outputs": [
1162 | {
1163 | "output_type": "stream",
1164 | "name": "stdout",
1165 | "text": [
1166 | "Digite o preço de compra: 30\n",
1167 | "Digite o preço de venda: 50\n",
1168 | "Lucro é maior que 20%.\n"
1169 | ]
1170 | }
1171 | ]
1172 | },
1173 | {
1174 | "cell_type": "markdown",
1175 | "source": [
1176 | "##Exercício 4"
1177 | ],
1178 | "metadata": {
1179 | "id": "QuItO62OT_Wp"
1180 | }
1181 | },
1182 | {
1183 | "cell_type": "code",
1184 | "source": [
1185 | "# Exercícios 2.9\n",
1186 | "# 4\n",
1187 | "# Solução do autor\n",
1188 | "\n",
1189 | "baixa = float(input(\"Baixa histórica = \"))\n",
1190 | "alta = float(input(\"Alta histórica = \"))\n",
1191 | "\n",
1192 | "suporte = baixa + (alta - baixa) * 0.3\n",
1193 | "resistencia = baixa + (alta - baixa) * 0.6\n",
1194 | "print(suporte, resistencia)\n",
1195 | "\n",
1196 | "preco_acao = float(input(\"Preço atual da ação = \"))\n",
1197 | "\n",
1198 | "if preco_acao >= suporte and preco_acao <= resistencia:\n",
1199 | " print(\"Dentro da faixa.\")\n",
1200 | "else:\n",
1201 | " print(\"Fora da faixa.\")"
1202 | ],
1203 | "metadata": {
1204 | "colab": {
1205 | "base_uri": "https://localhost:8080/"
1206 | },
1207 | "id": "ePcy-CA7T3fQ",
1208 | "outputId": "bfc7b3f9-b70a-4ec0-ca10-8910a3ff4e8b"
1209 | },
1210 | "execution_count": 34,
1211 | "outputs": [
1212 | {
1213 | "output_type": "stream",
1214 | "name": "stdout",
1215 | "text": [
1216 | "Baixa histórica = 20\n",
1217 | "Alta histórica = 40\n",
1218 | "26.0 32.0\n",
1219 | "Preço atual da ação = 29\n",
1220 | "Dentro da faixa.\n"
1221 | ]
1222 | }
1223 | ]
1224 | },
1225 | {
1226 | "cell_type": "code",
1227 | "source": [
1228 | "#Minha solução\n",
1229 | "baixa = float(input(\"Digite o preço da baixa histórica: \"))\n",
1230 | "alta = float(input(\"Digite o preço da alta histórica: \"))\n",
1231 | "atual = float(input(\"Digite o preço atual do ativo: \"))\n",
1232 | "\n",
1233 | "suporte = baixa + (alta - baixa) * 0.3\n",
1234 | "resistencia = float(baixa + (alta - baixa) * 0.6)\n",
1235 | "\n",
1236 | "print()\n",
1237 | "print('-------------Resultado-------------')\n",
1238 | "print(\"A resistência do ativo é em %.2f \" % resistencia)\n",
1239 | "print(\"O suporte do ativo é em %.2f \" % suporte)\n",
1240 | "\n",
1241 | "if atual <= resistencia and atual >= suporte:\n",
1242 | " print(\"O preço R$%.2f está dentro da faixa de suporte-resistência.\" % atual)\n",
1243 | "else:\n",
1244 | " print(\"O preço do ativo R$%.2f está fora da faixa de suporte-resistência.\" % atual)"
1245 | ],
1246 | "metadata": {
1247 | "colab": {
1248 | "base_uri": "https://localhost:8080/"
1249 | },
1250 | "id": "czUoG-2tUDwY",
1251 | "outputId": "94f2ca35-1436-44d1-cc58-87bca7cae8d4"
1252 | },
1253 | "execution_count": 35,
1254 | "outputs": [
1255 | {
1256 | "output_type": "stream",
1257 | "name": "stdout",
1258 | "text": [
1259 | "Digite o preço da baixa histórica: 20\n",
1260 | "Digite o preço da alta histórica: 40\n",
1261 | "Digite o preço atual do ativo: 29\n",
1262 | "\n",
1263 | "-------------Resultado-------------\n",
1264 | "A resistência do ativo é em 32.00 \n",
1265 | "O suporte do ativo é em 26.00 \n",
1266 | "O preço R$29.00 está dentro da faixa de suporte-resistência.\n"
1267 | ]
1268 | }
1269 | ]
1270 | },
1271 | {
1272 | "cell_type": "markdown",
1273 | "source": [
1274 | "##Exercício 5"
1275 | ],
1276 | "metadata": {
1277 | "id": "fhoGZcqlUbXg"
1278 | }
1279 | },
1280 | {
1281 | "cell_type": "code",
1282 | "source": [
1283 | "#Exercícios 2.9\n",
1284 | "# 5\n",
1285 | "# Solução do autor\n",
1286 | "\n",
1287 | "import math as mt\n",
1288 | "\n",
1289 | "a = float(input(\"A = \"))\n",
1290 | "b = float(input(\"B = \"))\n",
1291 | "c = float(input(\"C = \"))\n",
1292 | "\n",
1293 | "delta = b**2-4*a*c\n",
1294 | "\n",
1295 | "if delta >0:\n",
1296 | " x1 = (-b + mt.sqrt(delta))/(2 * a)\n",
1297 | " x2 = (-b - mt.sqrt(delta))/(2 * a)\n",
1298 | " print(\"Raiz 1 = \", x1, \"Raiz de 2 = \", x2)\n",
1299 | "elif delta == 0:\n",
1300 | " x1 = -b/(2 * a)\n",
1301 | " print(\"Duas raizes iguais a \", x1)\n",
1302 | "else:\n",
1303 | " print(\"Não existem raízes iguais.\")"
1304 | ],
1305 | "metadata": {
1306 | "colab": {
1307 | "base_uri": "https://localhost:8080/"
1308 | },
1309 | "id": "PU8KMwtiUVd3",
1310 | "outputId": "25b689da-dbc1-4f28-cf3e-d29831f95ae9"
1311 | },
1312 | "execution_count": 36,
1313 | "outputs": [
1314 | {
1315 | "output_type": "stream",
1316 | "name": "stdout",
1317 | "text": [
1318 | "A = 10\n",
1319 | "B = 35\n",
1320 | "C = 50\n",
1321 | "Não existem raízes iguais.\n"
1322 | ]
1323 | }
1324 | ]
1325 | },
1326 | {
1327 | "cell_type": "markdown",
1328 | "source": [
1329 | "##Exercício 6"
1330 | ],
1331 | "metadata": {
1332 | "id": "eFYCLoQjVMsQ"
1333 | }
1334 | },
1335 | {
1336 | "cell_type": "code",
1337 | "source": [
1338 | "# Exercícios 2.9\n",
1339 | "# 6\n",
1340 | "# Solução do autor\n",
1341 | "\n",
1342 | "compra = float(input(\"Valor da compra: \"))\n",
1343 | "\n",
1344 | "if compra <= 20:\n",
1345 | " desc = 0.05\n",
1346 | "elif compra <= 50:\n",
1347 | " desc = 0.1\n",
1348 | "elif compra <= 100:\n",
1349 | " desc = 0.15\n",
1350 | "elif compra <= 1000:\n",
1351 | " desc = 0.2\n",
1352 | "else:\n",
1353 | " desc = 0.3\n",
1354 | "\n",
1355 | "compraf = compra * (1-desc)\n",
1356 | "print(\"Valor da compra com desconto = \", compraf)"
1357 | ],
1358 | "metadata": {
1359 | "colab": {
1360 | "base_uri": "https://localhost:8080/"
1361 | },
1362 | "id": "dLd2_SrPVEVV",
1363 | "outputId": "6c9d7875-1d94-4d97-b760-ac0d9b7f64a8"
1364 | },
1365 | "execution_count": 37,
1366 | "outputs": [
1367 | {
1368 | "output_type": "stream",
1369 | "name": "stdout",
1370 | "text": [
1371 | "Valor da compra: 30\n",
1372 | "Valor da compra com desconto = 27.0\n"
1373 | ]
1374 | }
1375 | ]
1376 | },
1377 | {
1378 | "cell_type": "code",
1379 | "source": [
1380 | "# Minha solução\n",
1381 | "\n",
1382 | "compra = float(input(\"Digite o valor da compra: \"))\n",
1383 | "\n",
1384 | "if compra > 0 and compra <= 20:\n",
1385 | " total = compra - (compra * 0.05)\n",
1386 | " print(\"O valor com desconto de 5 porcento é:R$ %.2f\" % total)\n",
1387 | "\n",
1388 | "elif compra >= 21 and compra <= 50:\n",
1389 | " total = compra - (compra * 0.10)\n",
1390 | " print(\"O valor com desconto de 10 porcento é :R$ %.2f\" % total)\n",
1391 | "\n",
1392 | "elif compra >= 51 and compra <= 100:\n",
1393 | " total = compra - (compra * 0.15)\n",
1394 | " print(\"O valor com desconto de 15 porcento é :R$ %.2f\" % total)\n",
1395 | "\n",
1396 | "elif compra >= 101 and compra <= 1000:\n",
1397 | " total = compra - (compra * 0.20)\n",
1398 | " print(\"O valor com desconto de 20 porcento é :R$ %.2f\" % total)\n",
1399 | "\n",
1400 | "else:\n",
1401 | " total = compra - (compra * 0.30)\n",
1402 | " print(\"O valor com desconto de 30 porcento é :R$ %.2f\" % total)"
1403 | ],
1404 | "metadata": {
1405 | "colab": {
1406 | "base_uri": "https://localhost:8080/"
1407 | },
1408 | "id": "ywnbcPJlVSbG",
1409 | "outputId": "95b5e2bf-5a35-4055-ebb2-703125c4f246"
1410 | },
1411 | "execution_count": 38,
1412 | "outputs": [
1413 | {
1414 | "output_type": "stream",
1415 | "name": "stdout",
1416 | "text": [
1417 | "Digite o valor da compra: 30\n",
1418 | "O valor com desconto de 10 porcento é :R$ 27.00\n"
1419 | ]
1420 | }
1421 | ]
1422 | },
1423 | {
1424 | "cell_type": "markdown",
1425 | "source": [
1426 | "##Exercício 7\n"
1427 | ],
1428 | "metadata": {
1429 | "id": "IKVWQ46PVhvT"
1430 | }
1431 | },
1432 | {
1433 | "cell_type": "code",
1434 | "source": [
1435 | "# Exercícios 2.9\n",
1436 | "# 7\n",
1437 | "# Solução do autor\n",
1438 | "\n",
1439 | "n = int(input(\"Total de vendas (n) = \"))\n",
1440 | "# Zerando a soma dospares e ímpares\n",
1441 | "sp = 0\n",
1442 | "si = 0\n",
1443 | "\n",
1444 | "#+++++++++++ Aqui começa a interação +++++++++++\n",
1445 | "for i in range(n):\n",
1446 | " x = int(input(\"X = \"))\n",
1447 | " if x % 2 == 0:\n",
1448 | " sp = sp + x\n",
1449 | " else:\n",
1450 | " si = si + x\n",
1451 | "\n",
1452 | "print(\"Soma de pares = \", sp, \", Soma de ímpares = \", si)"
1453 | ],
1454 | "metadata": {
1455 | "colab": {
1456 | "base_uri": "https://localhost:8080/"
1457 | },
1458 | "id": "rkWHflhBVcRw",
1459 | "outputId": "c587af06-ed24-46ba-af32-5b82d6794661"
1460 | },
1461 | "execution_count": 40,
1462 | "outputs": [
1463 | {
1464 | "output_type": "stream",
1465 | "name": "stdout",
1466 | "text": [
1467 | "Total de vendas (n) = 5\n",
1468 | "X = 4\n",
1469 | "X = 6\n",
1470 | "X = 9\n",
1471 | "X = 8\n",
1472 | "X = 2\n",
1473 | "Soma de pares = 20 , Soma de ímpares = 9\n"
1474 | ]
1475 | }
1476 | ]
1477 | },
1478 | {
1479 | "cell_type": "markdown",
1480 | "source": [
1481 | "##Exercício 8\n"
1482 | ],
1483 | "metadata": {
1484 | "id": "OkNQR8zIVws_"
1485 | }
1486 | },
1487 | {
1488 | "cell_type": "code",
1489 | "source": [
1490 | "#Exercícios 2.9\n",
1491 | "# 8\n",
1492 | "# Solução do autor\n",
1493 | "\n",
1494 | "n = int(input(\"N = \"))\n",
1495 | "s = 0\n",
1496 | "for i in range(1, n + 1):\n",
1497 | " s = s + (70 - i +1)/(7 * i)\n",
1498 | "\n",
1499 | "print(\"Soma = \", s)"
1500 | ],
1501 | "metadata": {
1502 | "colab": {
1503 | "base_uri": "https://localhost:8080/"
1504 | },
1505 | "id": "hm_xopjEVmbu",
1506 | "outputId": "8380c527-f657-4341-eea1-028395071893"
1507 | },
1508 | "execution_count": 41,
1509 | "outputs": [
1510 | {
1511 | "output_type": "stream",
1512 | "name": "stdout",
1513 | "text": [
1514 | "N = 3\n",
1515 | "Soma = 18.166666666666668\n"
1516 | ]
1517 | }
1518 | ]
1519 | },
1520 | {
1521 | "cell_type": "markdown",
1522 | "source": [
1523 | "##Exercício 9"
1524 | ],
1525 | "metadata": {
1526 | "id": "5QpyEhslV9yQ"
1527 | }
1528 | },
1529 | {
1530 | "cell_type": "code",
1531 | "source": [
1532 | "# Exercícios 2.9\n",
1533 | "# 9\n",
1534 | "# Solução do autor\n",
1535 | "\n",
1536 | "n = int(input(\"N = \"))\n",
1537 | "cpar = 0\n",
1538 | "cimpar = 0\n",
1539 | "for i in range(1, n+1):\n",
1540 | " x = int(input(\"Entre com um número inteiro = \"))\n",
1541 | " if x% 2 == 0:\n",
1542 | " cpar = cpar + 1\n",
1543 | " else:\n",
1544 | " cimpar = cimpar + 1\n",
1545 | "\n",
1546 | "print(\"Quantidade de pares = \", cpar, \", Quantidade de impar = \", cimpar)"
1547 | ],
1548 | "metadata": {
1549 | "colab": {
1550 | "base_uri": "https://localhost:8080/"
1551 | },
1552 | "id": "_FclPJWQV3sM",
1553 | "outputId": "7fc56910-9679-4a25-8acd-8027c2cd2ce5"
1554 | },
1555 | "execution_count": 43,
1556 | "outputs": [
1557 | {
1558 | "output_type": "stream",
1559 | "name": "stdout",
1560 | "text": [
1561 | "N = 3\n",
1562 | "Entre com um número inteiro = 10\n",
1563 | "Entre com um número inteiro = 30\n",
1564 | "Entre com um número inteiro = 5\n",
1565 | "Quantidade de pares = 2 , Quantidade de impar = 1\n"
1566 | ]
1567 | }
1568 | ]
1569 | },
1570 | {
1571 | "cell_type": "markdown",
1572 | "source": [
1573 | "##Exercício 10"
1574 | ],
1575 | "metadata": {
1576 | "id": "fOUd9QoKWpPs"
1577 | }
1578 | },
1579 | {
1580 | "cell_type": "code",
1581 | "source": [
1582 | "# Exercícios 2.9\n",
1583 | "# 10\n",
1584 | "# Solução do autor\n",
1585 | "\n",
1586 | "n = int(input(\"N = \"))\n",
1587 | "x = float(input(\"X = \"))\n",
1588 | "s = x\n",
1589 | "imp = 1\n",
1590 | "fat = 1\n",
1591 | "for i in range(1, n):\n",
1592 | " fat = fat * i\n",
1593 | " imp = imp + 2\n",
1594 | " s = s + (x**imp)*(-1)**i/(imp * fat)\n",
1595 | "\n",
1596 | "print(\"Soma = \", s)"
1597 | ],
1598 | "metadata": {
1599 | "id": "lPyB4kIcWIbE"
1600 | },
1601 | "execution_count": null,
1602 | "outputs": []
1603 | },
1604 | {
1605 | "cell_type": "markdown",
1606 | "source": [
1607 | "##Exercício 11"
1608 | ],
1609 | "metadata": {
1610 | "id": "oSXZy5Z3WriT"
1611 | }
1612 | },
1613 | {
1614 | "cell_type": "code",
1615 | "source": [
1616 | "# Exercícios 2.9\n",
1617 | "# 11\n",
1618 | "# Solução do autor\n",
1619 | "\n",
1620 | "import math\n",
1621 | "i = 0\n",
1622 | "s = 0\n",
1623 | "imp = 1\n",
1624 | "dif = 10\n",
1625 | "while dif > 0.001:\n",
1626 | " i = i + 1\n",
1627 | " s = s + 4*(-1)**(i + 1)/ imp\n",
1628 | " imp = imp + 2\n",
1629 | " dif = abs(s - math.pi)\n",
1630 | "\n",
1631 | "print(\"S = \", s,\"diferença = \", dif,\"termos = \", i)"
1632 | ],
1633 | "metadata": {
1634 | "id": "LqRbAW9NWmKv"
1635 | },
1636 | "execution_count": null,
1637 | "outputs": []
1638 | },
1639 | {
1640 | "cell_type": "markdown",
1641 | "source": [
1642 | "##Exercício 12"
1643 | ],
1644 | "metadata": {
1645 | "id": "MK-8Q5sMW0BL"
1646 | }
1647 | },
1648 | {
1649 | "cell_type": "code",
1650 | "source": [
1651 | "# Exercícios 2.9\n",
1652 | "# 12\n",
1653 | "# Solução do autor\n",
1654 | "\n",
1655 | "n = int(input(\"Número de termos (n) = \"))\n",
1656 | "i = 2\n",
1657 | "s = 1\n",
1658 | "imp = 1\n",
1659 | "\n",
1660 | "while i < n:\n",
1661 | " imp = imp + 2\n",
1662 | " s = s + imp / i\n",
1663 | " i = i + 1\n",
1664 | "print(\"S = \", s)"
1665 | ],
1666 | "metadata": {
1667 | "colab": {
1668 | "base_uri": "https://localhost:8080/"
1669 | },
1670 | "id": "AyW7Tdv9WxWY",
1671 | "outputId": "8c7c0c18-6bd9-4308-e629-2a345abff7ef"
1672 | },
1673 | "execution_count": 44,
1674 | "outputs": [
1675 | {
1676 | "output_type": "stream",
1677 | "name": "stdout",
1678 | "text": [
1679 | "Número de termos (n) = 5\n",
1680 | "S = 5.916666666666667\n"
1681 | ]
1682 | }
1683 | ]
1684 | },
1685 | {
1686 | "cell_type": "markdown",
1687 | "source": [
1688 | "##Exercício 13"
1689 | ],
1690 | "metadata": {
1691 | "id": "LRLqtUAIXIZD"
1692 | }
1693 | },
1694 | {
1695 | "cell_type": "code",
1696 | "source": [
1697 | "# Exercícios 2.9\n",
1698 | "# 13\n",
1699 | "# Solução do autor\n",
1700 | "\n",
1701 | "lista = ['bbdc4','itub4','petr4','petr4','bbsa3','petr4','sanb4','petr4','bpac3','petr4']\n",
1702 | "n = len(lista)\n",
1703 | "i = 0\n",
1704 | "while i < n:\n",
1705 | " elemento = lista[i]\n",
1706 | " i = i + 1\n",
1707 | " if elemento == 'petr4': continue\n",
1708 | " print(\"Ação de Banco :\", elemento)"
1709 | ],
1710 | "metadata": {
1711 | "colab": {
1712 | "base_uri": "https://localhost:8080/"
1713 | },
1714 | "id": "asXmeOgIWyHs",
1715 | "outputId": "2cbc18ad-4f7e-42d6-bede-ca188f437f58"
1716 | },
1717 | "execution_count": 45,
1718 | "outputs": [
1719 | {
1720 | "output_type": "stream",
1721 | "name": "stdout",
1722 | "text": [
1723 | "Ação de Banco : bbdc4\n",
1724 | "Ação de Banco : itub4\n",
1725 | "Ação de Banco : bbsa3\n",
1726 | "Ação de Banco : sanb4\n",
1727 | "Ação de Banco : bpac3\n"
1728 | ]
1729 | }
1730 | ]
1731 | },
1732 | {
1733 | "cell_type": "markdown",
1734 | "source": [
1735 | "##Exercício 14"
1736 | ],
1737 | "metadata": {
1738 | "id": "IBHjdoAAXORp"
1739 | }
1740 | },
1741 | {
1742 | "cell_type": "code",
1743 | "source": [
1744 | "# Exercícios 2.9\n",
1745 | "# 14\n",
1746 | "# Solução do autor\n",
1747 | "\n",
1748 | "lista = ['bbdc4','itub4','petr4','petr4','bbsa3','petr4','sanb4','petr4','bpac3','petr4']\n",
1749 | "n = len(lista)\n",
1750 | "i = 0\n",
1751 | "while i < n:\n",
1752 | " elemento = lista[i]\n",
1753 | " if elemento == 'petr4':\n",
1754 | " print(\"Petrobras apareceu pela primeira vez no índice: \", i)\n",
1755 | " break\n",
1756 | " i = i + 1\n",
1757 | "print(\"+++ Fim da impressão +++\")"
1758 | ],
1759 | "metadata": {
1760 | "id": "KIGKBmJuXL2m"
1761 | },
1762 | "execution_count": null,
1763 | "outputs": []
1764 | },
1765 | {
1766 | "cell_type": "markdown",
1767 | "source": [
1768 | "##Exercício 15"
1769 | ],
1770 | "metadata": {
1771 | "id": "SM1P8c57XS6P"
1772 | }
1773 | },
1774 | {
1775 | "cell_type": "code",
1776 | "source": [
1777 | "# Exercícios 2.9\n",
1778 | "# 15\n",
1779 | "# Solução do autor\n",
1780 | "\n",
1781 | "lista = ['bbdc4','itub4','petr4','bbsa3','petr4','sanb4','petr4','bpac3','petr4']\n",
1782 | "n = len(lista)\n",
1783 | "i = 0\n",
1784 | "aparicao = 0\n",
1785 | "while i < n:\n",
1786 | " elemento = lista[i]\n",
1787 | " if elemento == 'petr4':\n",
1788 | " aparicao = aparicao + 1\n",
1789 | " if aparicao == 2:\n",
1790 | " print(\"Petrobras aparece a segunda vez no índice: \", i)\n",
1791 | " break\n",
1792 | " i = i + 1\n",
1793 | "print(\"+++ Fim da impressão +++\")"
1794 | ],
1795 | "metadata": {
1796 | "colab": {
1797 | "base_uri": "https://localhost:8080/"
1798 | },
1799 | "id": "1q_uHOfcXT8S",
1800 | "outputId": "37310137-eacc-439b-dc08-86f05c0178c5"
1801 | },
1802 | "execution_count": 46,
1803 | "outputs": [
1804 | {
1805 | "output_type": "stream",
1806 | "name": "stdout",
1807 | "text": [
1808 | "Petrobras aparece a segunda vez no índice: 4\n",
1809 | "+++ Fim da impressão +++\n"
1810 | ]
1811 | }
1812 | ]
1813 | },
1814 | {
1815 | "cell_type": "markdown",
1816 | "source": [
1817 | "##Exercício 16"
1818 | ],
1819 | "metadata": {
1820 | "id": "su1NSET5XZbI"
1821 | }
1822 | },
1823 | {
1824 | "cell_type": "code",
1825 | "source": [
1826 | "# Exercícios 2.9\n",
1827 | "# 16\n",
1828 | "# Solução do autor\n",
1829 | "\n",
1830 | "Palavras = [['comprar','vender'],['manter','alertar','indicar'],['tendencia','crash','lucro']]\n",
1831 | "i = 1\n",
1832 | "for p in Palavras:\n",
1833 | " print('elemento ',i, '=',p)\n",
1834 | " i = i + 1"
1835 | ],
1836 | "metadata": {
1837 | "colab": {
1838 | "base_uri": "https://localhost:8080/"
1839 | },
1840 | "id": "b8SuCDN_XWXI",
1841 | "outputId": "26299184-57ca-4b66-bf16-d3a9a15753a8"
1842 | },
1843 | "execution_count": 49,
1844 | "outputs": [
1845 | {
1846 | "output_type": "stream",
1847 | "name": "stdout",
1848 | "text": [
1849 | "elemento 1 = ['comprar', 'vender']\n",
1850 | "elemento 2 = ['manter', 'alertar', 'indicar']\n",
1851 | "elemento 3 = ['tendencia', 'crash', 'lucro']\n"
1852 | ]
1853 | }
1854 | ]
1855 | },
1856 | {
1857 | "cell_type": "markdown",
1858 | "source": [
1859 | "##Exercício 17"
1860 | ],
1861 | "metadata": {
1862 | "id": "AirVvwhHXfp5"
1863 | }
1864 | },
1865 | {
1866 | "cell_type": "code",
1867 | "source": [
1868 | "# Exercícios 2.9\n",
1869 | "# 17\n",
1870 | "# Solução do autor\n",
1871 | "\n",
1872 | "Palavras = [['comprar','vender'],['manter','alertar','indicar'],['tendencia','crash','lucro']]\n",
1873 | "i = 1 #Pra que?\n",
1874 | "for a in Palavras:\n",
1875 | " for num in a:\n",
1876 | " print(num)"
1877 | ],
1878 | "metadata": {
1879 | "colab": {
1880 | "base_uri": "https://localhost:8080/"
1881 | },
1882 | "id": "P5NLEF7TXcxy",
1883 | "outputId": "c895f912-99d1-4dff-9309-fa01f891f1a2"
1884 | },
1885 | "execution_count": 50,
1886 | "outputs": [
1887 | {
1888 | "output_type": "stream",
1889 | "name": "stdout",
1890 | "text": [
1891 | "comprar\n",
1892 | "vender\n",
1893 | "manter\n",
1894 | "alertar\n",
1895 | "indicar\n",
1896 | "tendencia\n",
1897 | "crash\n",
1898 | "lucro\n"
1899 | ]
1900 | }
1901 | ]
1902 | },
1903 | {
1904 | "cell_type": "code",
1905 | "source": [
1906 | "# Minha solução\n",
1907 | "Palavras = [['comprar','vender'],['manter','alertar','indicar'],['tendencia','crash','lucro']]\n",
1908 | "for p in Palavras:\n",
1909 | " for i in p:\n",
1910 | " print(i)"
1911 | ],
1912 | "metadata": {
1913 | "colab": {
1914 | "base_uri": "https://localhost:8080/"
1915 | },
1916 | "id": "j44JA-vUXjTH",
1917 | "outputId": "097ba774-65ea-4f02-c139-fa86cc36fc72"
1918 | },
1919 | "execution_count": 51,
1920 | "outputs": [
1921 | {
1922 | "output_type": "stream",
1923 | "name": "stdout",
1924 | "text": [
1925 | "comprar\n",
1926 | "vender\n",
1927 | "manter\n",
1928 | "alertar\n",
1929 | "indicar\n",
1930 | "tendencia\n",
1931 | "crash\n",
1932 | "lucro\n"
1933 | ]
1934 | }
1935 | ]
1936 | },
1937 | {
1938 | "cell_type": "markdown",
1939 | "source": [
1940 | "##Exercício 18"
1941 | ],
1942 | "metadata": {
1943 | "id": "CKTHHAWLXted"
1944 | }
1945 | },
1946 | {
1947 | "cell_type": "code",
1948 | "source": [
1949 | "# Exercícios 2.9\n",
1950 | "# 18\n",
1951 | "# Solução do autor\n",
1952 | "\n",
1953 | "import statistics as st\n",
1954 | "Lista = [[1,2,-1],[3,-1,4,5],[0,0,1,2,-1],[-1,-1,2,2,-1,2,-1],[3,2,0],[1,1,-1,0,2]]\n",
1955 | "i = 1\n",
1956 | "Lista_nova =[]\n",
1957 | "for x in Lista:\n",
1958 | " for num in x:\n",
1959 | " Lista_nova.append(num)\n",
1960 | "print(Lista_nova)\n",
1961 | "soma = sum(Lista_nova)\n",
1962 | "maximo = max(Lista_nova)\n",
1963 | "minimo = min(Lista_nova)\n",
1964 | "media = st.mean(Lista_nova)\n",
1965 | "moda = st.mode(Lista_nova)\n",
1966 | "desviop = st.pstdev(Lista_nova)\n",
1967 | "print(\"++++++++ RESULTADOS FINAIS ++++++++\")\n",
1968 | "print('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f' % (soma, maximo, minimo, media, moda, desviop))"
1969 | ],
1970 | "metadata": {
1971 | "colab": {
1972 | "base_uri": "https://localhost:8080/"
1973 | },
1974 | "id": "hYHWoeKAXpce",
1975 | "outputId": "c6c0028f-dd83-4b39-a728-9891f6680d58"
1976 | },
1977 | "execution_count": 52,
1978 | "outputs": [
1979 | {
1980 | "output_type": "stream",
1981 | "name": "stdout",
1982 | "text": [
1983 | "[1, 2, -1, 3, -1, 4, 5, 0, 0, 1, 2, -1, -1, -1, 2, 2, -1, 2, -1, 3, 2, 0, 1, 1, -1, 0, 2]\n",
1984 | "++++++++ RESULTADOS FINAIS ++++++++\n",
1985 | " 25.00 5.00 -1.00 0.93 -1.00 1.68\n"
1986 | ]
1987 | }
1988 | ]
1989 | },
1990 | {
1991 | "cell_type": "code",
1992 | "source": [
1993 | "# Minha solução\n",
1994 | "import statistics as st\n",
1995 | "Lista = [[1,2,-1],[3,-1,4,5],[0,0,1,2,-1],[-1,-1,2,2,-1,2,-1],[3,2,0],[1,1,-1,0,2]]\n",
1996 | "Lista_nova =[]\n",
1997 | "for i in Lista:\n",
1998 | " for j in i:\n",
1999 | " Lista_nova.append(j)\n",
2000 | "print(\"++++++++++++++++++++++++++++ Resultado ++++++++++++++++++++++++++\")\n",
2001 | "print(\"A nova lista: \",Lista_nova)\n",
2002 | "print(\"A Soma dos elementos dessa nova lista:\", sum(Lista_nova))\n",
2003 | "print(\"O maior elemento dessa nova lista:\", max(Lista_nova))\n",
2004 | "print(\"O menor elemento dessa nova lista:\", min(Lista_nova))\n",
2005 | "print(\"A média de elementos dessa lista:%.2f\" % st.mean(Lista_nova))\n",
2006 | "print(\"A moda de elementos dessa lista:%.2f\" % st.mode(Lista_nova))\n",
2007 | "print(\"O desvio-padrão populacional dessa lista:%.2f\" % st.pstdev(Lista_nova))"
2008 | ],
2009 | "metadata": {
2010 | "colab": {
2011 | "base_uri": "https://localhost:8080/"
2012 | },
2013 | "id": "z9CSJBVLXyHN",
2014 | "outputId": "e361c0d2-6c26-406c-de18-a4d0037274e4"
2015 | },
2016 | "execution_count": 53,
2017 | "outputs": [
2018 | {
2019 | "output_type": "stream",
2020 | "name": "stdout",
2021 | "text": [
2022 | "++++++++++++++++++++++++++++ Resultado ++++++++++++++++++++++++++\n",
2023 | "A nova lista: [1, 2, -1, 3, -1, 4, 5, 0, 0, 1, 2, -1, -1, -1, 2, 2, -1, 2, -1, 3, 2, 0, 1, 1, -1, 0, 2]\n",
2024 | "A Soma dos elementos dessa nova lista: 25\n",
2025 | "O maior elemento dessa nova lista: 5\n",
2026 | "O menor elemento dessa nova lista: -1\n",
2027 | "A média de elementos dessa lista:0.93\n",
2028 | "A moda de elementos dessa lista:-1.00\n",
2029 | "O desvio-padrão populacional dessa lista:1.68\n"
2030 | ]
2031 | }
2032 | ]
2033 | },
2034 | {
2035 | "cell_type": "markdown",
2036 | "source": [
2037 | "##Exercício 19"
2038 | ],
2039 | "metadata": {
2040 | "id": "30z4KS_3X_ir"
2041 | }
2042 | },
2043 | {
2044 | "cell_type": "code",
2045 | "source": [
2046 | "# Exercícios 2.9\n",
2047 | "# 19\n",
2048 | "# Solução do autor\n",
2049 | "\n",
2050 | "Lista = [['ontem','hoje','amanhã'],['sp','rj','mg','ce'],['são paulo','rio','santos','cuibá']]\n",
2051 | "i = 1 #Pra que?\n",
2052 | "Lista_nova = []\n",
2053 | "for x in Lista:\n",
2054 | " for palav in x:\n",
2055 | " Lista_nova.append(palav)\n",
2056 | "\n",
2057 | "print(\"++++++++++ Nova Lista ++++++++++\")\n",
2058 | "print(Lista_nova)\n",
2059 | "print(\"++++++++++ Lista Estendida ++++++++++\")\n",
2060 | "print(Lista_nova)\n",
2061 | "Lista_nova.extend(['férias','negócios'])\n",
2062 | "print(Lista_nova)\n",
2063 | "print(\"++++++++++ Lista Ordem Alfabética ++++++++++\")\n",
2064 | "Lista_nova.sort()\n",
2065 | "print(Lista_nova)"
2066 | ],
2067 | "metadata": {
2068 | "colab": {
2069 | "base_uri": "https://localhost:8080/"
2070 | },
2071 | "id": "FUoTrnBOX2NZ",
2072 | "outputId": "b0be09c5-1f3e-4ace-b516-e389d213736d"
2073 | },
2074 | "execution_count": 54,
2075 | "outputs": [
2076 | {
2077 | "output_type": "stream",
2078 | "name": "stdout",
2079 | "text": [
2080 | "++++++++++ Nova Lista ++++++++++\n",
2081 | "['ontem', 'hoje', 'amanhã', 'sp', 'rj', 'mg', 'ce', 'são paulo', 'rio', 'santos', 'cuibá']\n",
2082 | "++++++++++ Lista Estendida ++++++++++\n",
2083 | "['ontem', 'hoje', 'amanhã', 'sp', 'rj', 'mg', 'ce', 'são paulo', 'rio', 'santos', 'cuibá']\n",
2084 | "['ontem', 'hoje', 'amanhã', 'sp', 'rj', 'mg', 'ce', 'são paulo', 'rio', 'santos', 'cuibá', 'férias', 'negócios']\n",
2085 | "++++++++++ Lista Ordem Alfabética ++++++++++\n",
2086 | "['amanhã', 'ce', 'cuibá', 'férias', 'hoje', 'mg', 'negócios', 'ontem', 'rio', 'rj', 'santos', 'sp', 'são paulo']\n"
2087 | ]
2088 | }
2089 | ]
2090 | },
2091 | {
2092 | "cell_type": "code",
2093 | "source": [
2094 | "# Minha solução\n",
2095 | "Lista = [['ontem','hoje','amanhã'],['sp','rj','mg','ce'],['são paulo','rio','santos','cuibá']]\n",
2096 | "Lista_nova = []\n",
2097 | "\n",
2098 | "for i in Lista:\n",
2099 | " for j in i:\n",
2100 | " Lista_nova.append(j)\n",
2101 | "\n",
2102 | "add = ['férias','negócios']\n",
2103 | "Lista_nova.extend(add)\n",
2104 | "Lista_nova.sort()\n",
2105 | "print(Lista_nova)"
2106 | ],
2107 | "metadata": {
2108 | "colab": {
2109 | "base_uri": "https://localhost:8080/"
2110 | },
2111 | "id": "jkcCbtRLYD1m",
2112 | "outputId": "b6d37a49-6986-4f68-af87-fe041f710b78"
2113 | },
2114 | "execution_count": 55,
2115 | "outputs": [
2116 | {
2117 | "output_type": "stream",
2118 | "name": "stdout",
2119 | "text": [
2120 | "['amanhã', 'ce', 'cuibá', 'férias', 'hoje', 'mg', 'negócios', 'ontem', 'rio', 'rj', 'santos', 'sp', 'são paulo']\n"
2121 | ]
2122 | }
2123 | ]
2124 | },
2125 | {
2126 | "cell_type": "markdown",
2127 | "source": [
2128 | "##Exercício 20"
2129 | ],
2130 | "metadata": {
2131 | "id": "lV_GtpeoYPRQ"
2132 | }
2133 | },
2134 | {
2135 | "cell_type": "code",
2136 | "source": [
2137 | "# Exercícios 2.9\n",
2138 | "# 20\n",
2139 | "# Solução do autor\n",
2140 | "\n",
2141 | "let = ['a','b','c','a','d','f','a','b','b','d','c']\n",
2142 | "i = 1 # Pra que?\n",
2143 | "let_nov = []\n",
2144 | "\n",
2145 | "for i in let:\n",
2146 | " if i not in let_nov:\n",
2147 | " let_nov.append(i)\n",
2148 | "\n",
2149 | "print(\"+++++++++++ Nova Lista +++++++++++\")\n",
2150 | "print(let_nov)"
2151 | ],
2152 | "metadata": {
2153 | "colab": {
2154 | "base_uri": "https://localhost:8080/"
2155 | },
2156 | "id": "yZuxjJljYG9a",
2157 | "outputId": "55b56e5c-e224-4291-9034-ac6bcba3f0e9"
2158 | },
2159 | "execution_count": 56,
2160 | "outputs": [
2161 | {
2162 | "output_type": "stream",
2163 | "name": "stdout",
2164 | "text": [
2165 | "+++++++++++ Nova Lista +++++++++++\n",
2166 | "['a', 'b', 'c', 'd', 'f']\n"
2167 | ]
2168 | }
2169 | ]
2170 | },
2171 | {
2172 | "cell_type": "code",
2173 | "source": [
2174 | "# Minha solução\n",
2175 | "let = ['a','b','c','a','d','f','a','b','b','d','c']\n",
2176 | "nova_lista = []\n",
2177 | "\n",
2178 | "let.sort()\n",
2179 | "\n",
2180 | "anterior = []\n",
2181 | "for i in let:\n",
2182 | " if i == anterior:\n",
2183 | " continue\n",
2184 | " anterior = i\n",
2185 | " nova_lista.append(i)\n",
2186 | "\n",
2187 | "print(\"Nova lista sem repetição:\",nova_lista)"
2188 | ],
2189 | "metadata": {
2190 | "colab": {
2191 | "base_uri": "https://localhost:8080/"
2192 | },
2193 | "id": "sJfrKMAfYSvx",
2194 | "outputId": "5b5fc694-1869-4def-9929-76f0b113060f"
2195 | },
2196 | "execution_count": 57,
2197 | "outputs": [
2198 | {
2199 | "output_type": "stream",
2200 | "name": "stdout",
2201 | "text": [
2202 | "Nova lista sem repetição: ['a', 'b', 'c', 'd', 'f']\n"
2203 | ]
2204 | }
2205 | ]
2206 | }
2207 | ]
2208 | }
--------------------------------------------------------------------------------
/CAPÍTULO_5_PROGRAMANDO_FUNÇÕES.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "toc_visible": true,
8 | "authorship_tag": "ABX9TyPU5QnlBXefuzclgdaOrF7i",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | },
15 | "language_info": {
16 | "name": "python"
17 | }
18 | },
19 | "cells": [
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {
23 | "id": "view-in-github",
24 | "colab_type": "text"
25 | },
26 | "source": [
27 | "
"
28 | ]
29 | },
30 | {
31 | "cell_type": "markdown",
32 | "source": [
33 | "#CAPÍTULO 5 - PROGRAMANDO FUNÇÕES"
34 | ],
35 | "metadata": {
36 | "id": "nbM4zfNZeq6Q"
37 | }
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "source": [
42 | "#Exemplos"
43 | ],
44 | "metadata": {
45 | "id": "JepO346vVgfD"
46 | }
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "source": [
51 | "##Exemplo 5.1"
52 | ],
53 | "metadata": {
54 | "id": "Qa37WLVn9OLQ"
55 | }
56 | },
57 | {
58 | "cell_type": "code",
59 | "source": [
60 | "# Exemplo 5.1\n",
61 | "\n",
62 | "def nacional(pais):\n",
63 | " print('Eu venho do(a) ' + pais)\n",
64 | "\n",
65 | "\n",
66 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
67 | "n = int(input('Número de países = '))\n",
68 | "for i in range(n):\n",
69 | " local = input('Entre com seu país = ')\n",
70 | " nacional(local)"
71 | ],
72 | "metadata": {
73 | "colab": {
74 | "base_uri": "https://localhost:8080/"
75 | },
76 | "id": "N62QzpNgeukM",
77 | "outputId": "50573700-3816-40f3-c935-7afe4a8c30bb"
78 | },
79 | "execution_count": 1,
80 | "outputs": [
81 | {
82 | "output_type": "stream",
83 | "name": "stdout",
84 | "text": [
85 | "Número de países = 3\n",
86 | "Entre com seu país = Brasil\n",
87 | "Eu venho do(a) Brasil\n",
88 | "Entre com seu país = Argentina\n",
89 | "Eu venho do(a) Argentina\n",
90 | "Entre com seu país = Portugal\n",
91 | "Eu venho do(a) Portugal\n"
92 | ]
93 | }
94 | ]
95 | },
96 | {
97 | "cell_type": "markdown",
98 | "source": [
99 | "##Exemplo 5.2"
100 | ],
101 | "metadata": {
102 | "id": "uc6kz0E4fUVv"
103 | }
104 | },
105 | {
106 | "cell_type": "code",
107 | "source": [
108 | "# Exemplo 5.2\n",
109 | "\n",
110 | "def Imprime(nomes):\n",
111 | " for i in nomes:\n",
112 | " print(i)\n",
113 | "\n",
114 | "\n",
115 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
116 | "nomes = ['João', 'Maria', 'José', 'Ana']\n",
117 | "\n",
118 | "Imprime(nomes)"
119 | ],
120 | "metadata": {
121 | "colab": {
122 | "base_uri": "https://localhost:8080/"
123 | },
124 | "id": "n0hI2-a0fY1o",
125 | "outputId": "5363a041-2cd1-4e5a-eb3f-438d44e93f63"
126 | },
127 | "execution_count": 2,
128 | "outputs": [
129 | {
130 | "output_type": "stream",
131 | "name": "stdout",
132 | "text": [
133 | "João\n",
134 | "Maria\n",
135 | "José\n",
136 | "Ana\n"
137 | ]
138 | }
139 | ]
140 | },
141 | {
142 | "cell_type": "markdown",
143 | "source": [
144 | "##Exemplo 5.3"
145 | ],
146 | "metadata": {
147 | "id": "qvfra-SA3YO0"
148 | }
149 | },
150 | {
151 | "cell_type": "code",
152 | "source": [
153 | "# Exemplo 5.3\n",
154 | "\n",
155 | "def calculo(x):\n",
156 | " y = 5 * x\n",
157 | " return(y)\n",
158 | "\n",
159 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
160 | "print(calculo(5))\n",
161 | "print(calculo(3))\n",
162 | "print(calculo(8))\n",
163 | "print(calculo(7))"
164 | ],
165 | "metadata": {
166 | "colab": {
167 | "base_uri": "https://localhost:8080/"
168 | },
169 | "id": "nT-HA1ls7WrO",
170 | "outputId": "5eb342b0-8b52-4820-9860-1cc1dc512771"
171 | },
172 | "execution_count": 3,
173 | "outputs": [
174 | {
175 | "output_type": "stream",
176 | "name": "stdout",
177 | "text": [
178 | "25\n",
179 | "15\n",
180 | "40\n",
181 | "35\n"
182 | ]
183 | }
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "source": [
189 | "##Exemplo 5.4"
190 | ],
191 | "metadata": {
192 | "id": "G_Rrrg363V2E"
193 | }
194 | },
195 | {
196 | "cell_type": "code",
197 | "source": [
198 | "# Exemplo 5.4\n",
199 | "\n",
200 | "def verifica(n):\n",
201 | " if n % 2 == 0:\n",
202 | " print('Par')\n",
203 | " else:\n",
204 | " print('Impar')\n",
205 | "\n",
206 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
207 | "n = int(input('Entre com o número = '))\n",
208 | "\n",
209 | "verifica(n)"
210 | ],
211 | "metadata": {
212 | "colab": {
213 | "base_uri": "https://localhost:8080/"
214 | },
215 | "id": "lpaSMFA57jIJ",
216 | "outputId": "715f7a5f-8d69-4035-d69d-3e11029c0419"
217 | },
218 | "execution_count": 5,
219 | "outputs": [
220 | {
221 | "output_type": "stream",
222 | "name": "stdout",
223 | "text": [
224 | "Entre com o número = 10\n",
225 | "Par\n"
226 | ]
227 | }
228 | ]
229 | },
230 | {
231 | "cell_type": "code",
232 | "source": [
233 | "def calculo(x):\n",
234 | " y = 5 * x\n",
235 | " return(y)\n",
236 | "\n",
237 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
238 | "a = calculo(5)\n",
239 | "print('++++ Resultado ++++')\n",
240 | "print(a)"
241 | ],
242 | "metadata": {
243 | "colab": {
244 | "base_uri": "https://localhost:8080/"
245 | },
246 | "id": "jwO8k1u77xgb",
247 | "outputId": "5c80e34b-a8d8-4ae0-89ff-d1e88ffd4d7b"
248 | },
249 | "execution_count": 6,
250 | "outputs": [
251 | {
252 | "output_type": "stream",
253 | "name": "stdout",
254 | "text": [
255 | "++++ Resultado ++++\n",
256 | "25\n"
257 | ]
258 | }
259 | ]
260 | },
261 | {
262 | "cell_type": "markdown",
263 | "source": [
264 | "##Exemplo 5.5"
265 | ],
266 | "metadata": {
267 | "id": "ll_hFzSofUYP"
268 | }
269 | },
270 | {
271 | "cell_type": "code",
272 | "source": [
273 | "# Exemplo 5.5\n",
274 | "\n",
275 | "def cidade(tam):\n",
276 | " if (tam <= 30000):\n",
277 | " return 'Pequena'\n",
278 | " if (tam > 30000) and (tam <= 150000) :\n",
279 | " return 'Média'\n",
280 | " if (tam > 150000) and (tam <= 600000) :\n",
281 | " return 'Grande'\n",
282 | " else:\n",
283 | " return 'Metrópole'\n",
284 | "\n",
285 | "tamanho = float(input('Entre com a população = '))\n",
286 | "a = cidade(tamanho)\n",
287 | "print('++++++ Categoria da cidade ++++++\\n')\n",
288 | "print(a)"
289 | ],
290 | "metadata": {
291 | "colab": {
292 | "base_uri": "https://localhost:8080/"
293 | },
294 | "id": "sOe5ftnL3R-S",
295 | "outputId": "6f3bfac5-19cd-47dc-d1a2-2d5c7efeb77a"
296 | },
297 | "execution_count": 9,
298 | "outputs": [
299 | {
300 | "output_type": "stream",
301 | "name": "stdout",
302 | "text": [
303 | "Entre com a população = 175000\n",
304 | "++++++ Categoria da cidade ++++++\n",
305 | "\n",
306 | "Grande\n"
307 | ]
308 | }
309 | ]
310 | },
311 | {
312 | "cell_type": "markdown",
313 | "source": [
314 | "##Exemplo 5.6"
315 | ],
316 | "metadata": {
317 | "id": "M-vQ2Qe_3ezc"
318 | }
319 | },
320 | {
321 | "cell_type": "code",
322 | "source": [
323 | "# Exemplo 5.6\n",
324 | "\n",
325 | "import math\n",
326 | "\n",
327 | "def delta(a, b, c):\n",
328 | " delta = b**2 - 4 * a * c\n",
329 | " if (delta > 0):\n",
330 | " x1 = (- b + math.sqrt(delta)) / (2 * a)\n",
331 | " x2 = (- b - math.sqrt(delta)) / (2 * a)\n",
332 | " return x1, x2\n",
333 | " elif (delta == 0):\n",
334 | " x1 = -b/(2 * a)\n",
335 | " return x1\n",
336 | " else:\n",
337 | " return 'Não existem raízes reaís.'\n",
338 | "\n",
339 | "\n",
340 | "a = float(input('a = '))\n",
341 | "b = float(input('b = '))\n",
342 | "c = float(input('c = '))\n",
343 | "resp = delta(a, b, c)\n",
344 | "print('++++++ Solução da eq. 2º. grau ++++++\\n')\n",
345 | "print(resp)"
346 | ],
347 | "metadata": {
348 | "colab": {
349 | "base_uri": "https://localhost:8080/"
350 | },
351 | "id": "NRD15dad8rid",
352 | "outputId": "f13523d4-d07c-4d3b-9714-88da095f747d"
353 | },
354 | "execution_count": 12,
355 | "outputs": [
356 | {
357 | "output_type": "stream",
358 | "name": "stdout",
359 | "text": [
360 | "a = 1\n",
361 | "b = -5\n",
362 | "c = 6\n",
363 | "++++++ Solução da eq. 2º. grau ++++++\n",
364 | "\n",
365 | "(3.0, 2.0)\n"
366 | ]
367 | }
368 | ]
369 | },
370 | {
371 | "cell_type": "markdown",
372 | "source": [
373 | "##Exemplo 5.7"
374 | ],
375 | "metadata": {
376 | "id": "_zjxH60dfUa9"
377 | }
378 | },
379 | {
380 | "cell_type": "code",
381 | "source": [
382 | "# Biblioteca das minhas funções\n",
383 | "\n",
384 | "#Programa com duas funcoes para media e desvioP\n",
385 | "import statistics as stat\n",
386 | "\n",
387 | "def media(lista):\n",
388 | " x = stat.mean(lista)\n",
389 | " return(x)\n",
390 | "\n",
391 | "def desvio(lista):\n",
392 | " y = stat.pstdev(lista)\n",
393 | " return(y)"
394 | ],
395 | "metadata": {
396 | "id": "B46Z2VaA8c8H"
397 | },
398 | "execution_count": 10,
399 | "outputs": []
400 | },
401 | {
402 | "cell_type": "code",
403 | "source": [
404 | "# Exemplo 5.7\n",
405 | "\n",
406 | "#Programa principal para chamar func. ext.\n",
407 | "\n",
408 | "import Bib\n",
409 | "\n",
410 | "numeros = [1, 10, 3, 2, 1, 5, 5, 4, 0, 1, 2]\n",
411 | "resp1 = Bib.media(numeros)\n",
412 | "resp2 = Bib.desvio(numeros)\n",
413 | "\n",
414 | "print('+++++++ Respostas ++++++')\n",
415 | "print('Média = ', resp1, ' desvio padrão = ', resp2)"
416 | ],
417 | "metadata": {
418 | "id": "Px7WDQ-O8lyf"
419 | },
420 | "execution_count": null,
421 | "outputs": []
422 | },
423 | {
424 | "cell_type": "markdown",
425 | "source": [
426 | "#Exercícios 5.4"
427 | ],
428 | "metadata": {
429 | "id": "pvrqPEEzJuqh"
430 | }
431 | },
432 | {
433 | "cell_type": "markdown",
434 | "source": [
435 | "##Exercício 1"
436 | ],
437 | "metadata": {
438 | "id": "eUVGeJd-Jzc6"
439 | }
440 | },
441 | {
442 | "cell_type": "code",
443 | "source": [
444 | "# Exercícios 5.4\n",
445 | "# 1\n",
446 | "# Minha solução\n",
447 | "\n",
448 | "def soma(a, b):\n",
449 | " sma = a + b\n",
450 | " return sma\n",
451 | "\n",
452 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
453 | "\n",
454 | "a = int(input('Digíte o parametro A = '))\n",
455 | "b = int(input('Digíte o parametro B = '))\n",
456 | "print('Soma =', soma(a, b))"
457 | ],
458 | "metadata": {
459 | "colab": {
460 | "base_uri": "https://localhost:8080/"
461 | },
462 | "id": "EGzPnM549GfU",
463 | "outputId": "c967cc75-dbc3-4c5a-8745-fb87820c8a88"
464 | },
465 | "execution_count": 15,
466 | "outputs": [
467 | {
468 | "output_type": "stream",
469 | "name": "stdout",
470 | "text": [
471 | "Digíte o parametro A = 10\n",
472 | "Digíte o parametro B = 4\n",
473 | "Soma = 14\n"
474 | ]
475 | }
476 | ]
477 | },
478 | {
479 | "cell_type": "markdown",
480 | "source": [
481 | "##Exercício 2"
482 | ],
483 | "metadata": {
484 | "id": "_XNe2iV69ZJp"
485 | }
486 | },
487 | {
488 | "cell_type": "code",
489 | "source": [
490 | "# Exercícios 5.4\n",
491 | "# 2\n",
492 | "# Minha solução\n",
493 | "\n",
494 | "def calculo(a,b,c):\n",
495 | " y = a**3 - a * b + b**2 - b*c\n",
496 | " return y\n",
497 | "\n",
498 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
499 | "\n",
500 | "a = int(input('Digíte o parametro A = '))\n",
501 | "b = int(input('Digíte o parametro B = '))\n",
502 | "c = int(input('Digíte o parametro C = '))\n",
503 | "\n",
504 | "print('Resultado =', calculo(a, b, c))"
505 | ],
506 | "metadata": {
507 | "colab": {
508 | "base_uri": "https://localhost:8080/"
509 | },
510 | "id": "ubqDy9lf9QvS",
511 | "outputId": "d24e18f4-616b-4f1b-cdb1-a1cb9625f5bc"
512 | },
513 | "execution_count": 16,
514 | "outputs": [
515 | {
516 | "output_type": "stream",
517 | "name": "stdout",
518 | "text": [
519 | "Digíte o parametro A = 1\n",
520 | "Digíte o parametro B = 2\n",
521 | "Digíte o parametro C = 3\n",
522 | "Resultado = -3\n"
523 | ]
524 | }
525 | ]
526 | },
527 | {
528 | "cell_type": "markdown",
529 | "source": [
530 | "##Exercício 3"
531 | ],
532 | "metadata": {
533 | "id": "b66XViqQ9u3m"
534 | }
535 | },
536 | {
537 | "cell_type": "code",
538 | "source": [
539 | "# Exercícios 5.4\n",
540 | "# 3\n",
541 | "# Minha solução\n",
542 | "\n",
543 | "import math\n",
544 | "\n",
545 | "def calculo(a,b):\n",
546 | " y = math.sqrt(a**2 + b**2) - math.sin(a) + math.cos(a + b)\n",
547 | " return y\n",
548 | "\n",
549 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
550 | "a = float(input('Digíte o parametro A = '))\n",
551 | "b = float(input('Digíte o parametro B = '))\n",
552 | "\n",
553 | "print('Resultado =', calculo(a, b))"
554 | ],
555 | "metadata": {
556 | "colab": {
557 | "base_uri": "https://localhost:8080/"
558 | },
559 | "id": "pZKhYvPS9xH8",
560 | "outputId": "6ec88a0a-3dc4-4c7b-8b2e-69c6ccbeee23"
561 | },
562 | "execution_count": 18,
563 | "outputs": [
564 | {
565 | "output_type": "stream",
566 | "name": "stdout",
567 | "text": [
568 | "Digíte o parametro A = 0.5\n",
569 | "Digíte o parametro B = 0.7\n",
570 | "Resultado = 0.7431647425767333\n"
571 | ]
572 | }
573 | ]
574 | },
575 | {
576 | "cell_type": "markdown",
577 | "source": [
578 | "##Exercício 4"
579 | ],
580 | "metadata": {
581 | "id": "4F-PZh8i-ojD"
582 | }
583 | },
584 | {
585 | "cell_type": "code",
586 | "source": [
587 | "# Exercícios 5.4\n",
588 | "# 4\n",
589 | "# Minha solução\n",
590 | "\n",
591 | "def calculo(x,y):\n",
592 | " if x >= y:\n",
593 | " z = x + y\n",
594 | " return z\n",
595 | " elif x < y:\n",
596 | " z = x - y\n",
597 | " return z\n",
598 | "\n",
599 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
600 | "X = int(input('Digíte o parametro X = '))\n",
601 | "Y = int(input('Digíte o parametro Y = '))\n",
602 | "\n",
603 | "print('Resultado =', calculo(X, Y))"
604 | ],
605 | "metadata": {
606 | "colab": {
607 | "base_uri": "https://localhost:8080/"
608 | },
609 | "id": "YMrjK7e--JbW",
610 | "outputId": "f1caa99b-d4b2-45dc-cdcf-6022bc0bd015"
611 | },
612 | "execution_count": 19,
613 | "outputs": [
614 | {
615 | "output_type": "stream",
616 | "name": "stdout",
617 | "text": [
618 | "Digíte o parametro X = 10\n",
619 | "Digíte o parametro Y = 4\n",
620 | "Resultado = 14\n"
621 | ]
622 | }
623 | ]
624 | },
625 | {
626 | "cell_type": "markdown",
627 | "source": [
628 | "##Exercício 5"
629 | ],
630 | "metadata": {
631 | "id": "aXJfD3Oj-0Q3"
632 | }
633 | },
634 | {
635 | "cell_type": "code",
636 | "source": [
637 | "# Exercícios 5.4\n",
638 | "# 5\n",
639 | "# Minha solução\n",
640 | "\n",
641 | "def contagem(lista):\n",
642 | " if len(lista) > 4:\n",
643 | " return lista[-1]\n",
644 | " elif len(lista) < 4:\n",
645 | " return lista[0]\n",
646 | "\n",
647 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
648 | "lista = ['banana','abacate','maçã','goiaba','morango','abacaxi']\n",
649 | "\n",
650 | "print(contagem(lista))"
651 | ],
652 | "metadata": {
653 | "colab": {
654 | "base_uri": "https://localhost:8080/"
655 | },
656 | "id": "MCWZjKUb-t_Q",
657 | "outputId": "aabab3b6-e38b-4a6b-9b41-8ee1bea8a8f2"
658 | },
659 | "execution_count": 20,
660 | "outputs": [
661 | {
662 | "output_type": "stream",
663 | "name": "stdout",
664 | "text": [
665 | "abacaxi\n"
666 | ]
667 | }
668 | ]
669 | },
670 | {
671 | "cell_type": "markdown",
672 | "source": [
673 | "##Exercício 6"
674 | ],
675 | "metadata": {
676 | "id": "4ppTEkSn-8T4"
677 | }
678 | },
679 | {
680 | "cell_type": "code",
681 | "source": [
682 | "# Exercícios 5.4\n",
683 | "# 6\n",
684 | "# Minha solução\n",
685 | "\n",
686 | "def encontrarIndex(encontrar, lis):\n",
687 | " index = lis.index(str(encontrar))\n",
688 | " return index\n",
689 | "\n",
690 | "\n",
691 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
692 | "lista = ['dow','ibov','ftse','dax','nasdaq','cac']\n",
693 | "\n",
694 | "n = input('Digite nome para encontrar índice = ')\n",
695 | "print(encontrarIndex(n, lista))"
696 | ],
697 | "metadata": {
698 | "colab": {
699 | "base_uri": "https://localhost:8080/"
700 | },
701 | "id": "-UnDXW-H-5ZA",
702 | "outputId": "d686c1ba-be94-4d97-a677-ceb814e7d3eb"
703 | },
704 | "execution_count": 22,
705 | "outputs": [
706 | {
707 | "output_type": "stream",
708 | "name": "stdout",
709 | "text": [
710 | "Digite nome para encontrar índice = nasdaq\n",
711 | "4\n"
712 | ]
713 | }
714 | ]
715 | },
716 | {
717 | "cell_type": "markdown",
718 | "source": [
719 | "##Exercício 7"
720 | ],
721 | "metadata": {
722 | "id": "OhCjnRPd_vnW"
723 | }
724 | },
725 | {
726 | "cell_type": "code",
727 | "source": [
728 | "# Exercícios 5.4\n",
729 | "# 7\n",
730 | "# Minha solução\n",
731 | "\n",
732 | "def removerIndex(encontrar, lis):\n",
733 | " lis.remove(str(encontrar))\n",
734 | " return lis\n",
735 | "\n",
736 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
737 | "lista = ['dow','ibov','ftse','dax','nasdaq','cac']\n",
738 | "\n",
739 | "n = input('Digite nome para encontrar índice = ')\n",
740 | "print(removerIndex(n, lista))"
741 | ],
742 | "metadata": {
743 | "colab": {
744 | "base_uri": "https://localhost:8080/"
745 | },
746 | "id": "ACVUhEYi_BiE",
747 | "outputId": "8199b387-ab24-42ef-941a-43a43ff95be1"
748 | },
749 | "execution_count": 23,
750 | "outputs": [
751 | {
752 | "output_type": "stream",
753 | "name": "stdout",
754 | "text": [
755 | "Digite nome para encontrar índice = cac\n",
756 | "['dow', 'ibov', 'ftse', 'dax', 'nasdaq']\n"
757 | ]
758 | }
759 | ]
760 | },
761 | {
762 | "cell_type": "markdown",
763 | "source": [
764 | "##Exercício 8"
765 | ],
766 | "metadata": {
767 | "id": "yZuLqltrBXe-"
768 | }
769 | },
770 | {
771 | "cell_type": "code",
772 | "source": [
773 | "# Exercícios 5.4\n",
774 | "# 8\n",
775 | "# Minha solução\n",
776 | "\n",
777 | "def repeticao(valor,lista):\n",
778 | " total = lista.count(valor)\n",
779 | " return total\n",
780 | "\n",
781 | "#+++++++++++++++++ Aqui começa o programa principal ++++++++++++++++++++++++++\n",
782 | "\n",
783 | "Num = [3,3,4,1,2,1,1,2,3,4,4,1,1,5,2]\n",
784 | "\n",
785 | "cont = int(input('Digite número a ser contado = '))\n",
786 | "\n",
787 | "print(repeticao(cont, Num))"
788 | ],
789 | "metadata": {
790 | "colab": {
791 | "base_uri": "https://localhost:8080/"
792 | },
793 | "id": "3sLOBcxxBP9Z",
794 | "outputId": "8881a63d-96e1-4db7-a830-1f1a65feb919"
795 | },
796 | "execution_count": 24,
797 | "outputs": [
798 | {
799 | "output_type": "stream",
800 | "name": "stdout",
801 | "text": [
802 | "Digite número a ser contado =1\n",
803 | "5\n"
804 | ]
805 | }
806 | ]
807 | },
808 | {
809 | "cell_type": "markdown",
810 | "source": [
811 | "##Exercício 9"
812 | ],
813 | "metadata": {
814 | "id": "teZ_0AcbBqr1"
815 | }
816 | },
817 | {
818 | "cell_type": "code",
819 | "source": [
820 | "# Exercícios 5.4\n",
821 | "# 9\n",
822 | "# Biblioteca Minhas Funções\n",
823 | "\n",
824 | "import statistics as st\n",
825 | "import numpy as ny\n",
826 | "\n",
827 | "def media(lista1, lista2):\n",
828 | " M_lista1 = st.median(lista1)\n",
829 | " M_lista2 = st.median(lista2)\n",
830 | " return M_lista1, M_lista2\n",
831 | "\n",
832 | "def desvio(lista1, lista2):\n",
833 | " M_lista1 = st.stdev(lista1)\n",
834 | " M_lista2 = st.stdev(lista2)\n",
835 | " return M_lista1, M_lista2\n",
836 | "\n",
837 | "def retornos(lista1, lista2):\n",
838 | " arr1 = ny.array(lista1)\n",
839 | " arr2 = ny.array(lista2)\n",
840 | "\n",
841 | " nret1 = len(lista1)\n",
842 | " nret2 = len(lista2)\n",
843 | "\n",
844 | " retorno1 = (arr1[1:nret1] - arr1[0:nret1-1] / arr1[0:nret1-1])\n",
845 | " retorno2 = (arr2[1:nret2] - arr2[0:nret2-1] / arr2[0:nret2-1])\n",
846 | " return retorno1, retorno2\n",
847 | "\n",
848 | "def maximo(lista1, lista2):\n",
849 | " list1 = max(lista1)\n",
850 | " list2 = max(lista2)\n",
851 | " return list1, list2"
852 | ],
853 | "metadata": {
854 | "id": "11dklXlzB0Sr"
855 | },
856 | "execution_count": null,
857 | "outputs": []
858 | },
859 | {
860 | "cell_type": "code",
861 | "source": [
862 | "# Exercícios 5.4\n",
863 | "# 9\n",
864 | "# Minha solução\n",
865 | "\n",
866 | "import Minhas_Funções as MF\n",
867 | "\n",
868 | "PETR4 = [9.72, 10.69, 11.82, 12.93, 12.92, 12.82, 13.64, 13.79, 13.78, 13.08,\n",
869 | " 12.67, 12.83]\n",
870 | "\n",
871 | "PETRF42 = [0.2, 0.46, 0.82, 1.38, 1.46, 1.24, 1.69, 1.75, 1.6, 1.02, 0.64, 0.58]\n",
872 | "\n",
873 | "print('Média de cada lista', MF.media(PETR4,PETRF42))\n",
874 | "print('Desvio-padrão de cada lista', MF.desvio(PETR4,PETRF42))\n",
875 | "print('Retornos de cada lista', MF.retornos(PETR4,PETRF42))\n",
876 | "print('Maximo de cada lista', MF.maximo(PETR4,PETRF42))"
877 | ],
878 | "metadata": {
879 | "id": "ywqTV3iOBb28"
880 | },
881 | "execution_count": 25,
882 | "outputs": []
883 | }
884 | ]
885 | }
--------------------------------------------------------------------------------
/Dados/Capítulo 1/Dados_vale__Gerdau.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 1/Dados_vale__Gerdau.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 1/Petrobras.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 1/Petrobras.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 1/bov.txt:
--------------------------------------------------------------------------------
1 | petr4 vale3 ggbr4 28.40 31.30 15.76
2 |
--------------------------------------------------------------------------------
/Dados/Capítulo 3/BitCoin.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/BitCoin.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/Dow Jones.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/Dow Jones.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/ExPy.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/ExPy.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/ExercPy.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/ExercPy.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/IBOV x PETR4.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/IBOV x PETR4.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/Ibv.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/Ibv.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/Ibv_Junto.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/Ibv_Junto.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/ListaDupla.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/ListaDupla.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/PETR4.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/PETR4.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 3/VALE3.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 3/VALE3.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 6/Ibov.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 6/Ibov.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 6/PetrTitul.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 6/PetrTitul.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 6/Titulos.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 6/Titulos.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 7/BBrasil_intra.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 7/BBrasil_intra.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 7/Dados 7.4 - 2.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 7/Dados 7.4 - 2.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 7/Vale3.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 7/Vale3.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 7/cotação.txt:
--------------------------------------------------------------------------------
1 | 07/09/2019 30.4 10.7
2 | 08/09/2019 31.5 10.8
3 | 09/09/2019 33.78 10.9
4 | 10/09/2019 28.75 14.5
5 | 11/09/2019 25.1 19.1
6 |
--------------------------------------------------------------------------------
/Dados/Capítulo 7/datas.txt:
--------------------------------------------------------------------------------
1 | 01/02/2019 23.5
2 | 02/02/2019 25.8
3 | 02/04/2019 33.78
4 | 04/04/2019 28.75
5 | 07/05/2019 25.1
--------------------------------------------------------------------------------
/Dados/Capítulo 8/Book_Ex.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 8/Book_Ex.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 8/Grupos.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 8/Grupos.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 8/Ibv_crise_2008.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 8/Ibv_crise_2008.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/BBrasil.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/BBrasil.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/Bov2008.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/Bov2008.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/Ibovespa.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/Ibovespa.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/OpcaoSmile.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/OpcaoSmile.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/Portfolio_Bov.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/Portfolio_Bov.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/Portfolio_Moedas.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/Portfolio_Moedas.xlsx
--------------------------------------------------------------------------------
/Dados/Capítulo 9/Portfolio_Moedas.xlsx.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GustavoRosso/PythonEMercadoFinanceiro/90ff8e5eea85d3979b7d53cfde17e0df330b6df8/Dados/Capítulo 9/Portfolio_Moedas.xlsx.txt
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Gustavo Rosso
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python e Mercado Financeiro: Exemplos e Exercícios Resolvidos
2 |
3 | Este repositório contém todos os dados, exemplos e exercícios resolvidos por mim com base no livro "Python e Mercado Financeiro: Programação Para Estudantes, Investidores e Analistas". Quero deixar claro que os códigos presentes neste repositório foram desenvolvidos independentemente por mim e não são diretamente fornecidos, endossados ou revisados pelo autor do livro ou pela editora.
4 |
5 | ## Sobre o Livro
6 |
7 |
8 |
9 | **Título:** Python e Mercado Financeiro: Programação Para Estudantes, Investidores e Analistas
10 |
11 | **Autor:** Marco Antonio Leonel Caetano
12 |
13 | **Editora:** Blucher; 1ª edição (21 maio 2021) - https://www.blucher.com.br/
14 |
15 | **Link para Compra:** Amazon
16 |
17 | O livro "Python e Mercado Financeiro" é uma referência essencial para quem deseja aprender a utilizar Python para análise e visualização de dados financeiros, bem como para desenvolver estratégias de investimento automatizadas. Este repositório foi criado para acompanhar o livro e fornecer exemplos práticos, exercícios resolvidos e recursos adicionais.
18 |
19 | ## Conteúdo
20 |
21 | - [Capítulo 1 - Princípios de Programação](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_1_PRINC%C3%8DPIOS_DE_PROGRAMA%C3%87%C3%83O.ipynb)
22 | - [Capítulo 2 - Análise de Dados Financeiros](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_2_ITERA%C3%87%C3%83O_E_DECIS%C3%83O.ipynb)
23 | - [Capítulo 3 - Estratégias de Investimento](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_3_EXPLORA%C3%87%C3%83O_A_ESTAT%C3%8DSTICA_NO_MERCADO.ipynb)
24 | - [Capítulo 4 - Visualização de Dados Financeiros](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_4_GR%C3%81FICOS_PARA_AN%C3%81LISES_E_OPERA%C3%87%C3%95ES.ipynb)
25 | - [Capítulo 5 - Programando Funções](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_5_PROGRAMANDO_FUN%C3%87%C3%95ES.ipynb)
26 | - [Capítulo 6 - A Dinâmica do Array](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_6_A_DIN%C3%83MICA_DO_ARRAY.ipynb)
27 | - [Capítulo 7 - As Bibliotecas Time e Datetime](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_7_AS_BIBLIOTECAS_TIME_E_DATETIME.ipynb)
28 | - [Capítulo 8 - A Biblioteca Pandas](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_8_A_BIBLIOTECA_PANDAS.ipynb)
29 | - [Capítulo 9 - Finanças E Python](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_9_FINAN%C3%87AS_E_PYTHON.ipynb)
30 | - [Capítulo 10 - Datareader e Análises com Yahoo! Finance](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_10_DATAREADER_E_AN%C3%81LISES_COM_YAHOO!_FINANCE.ipynb)
31 | - [Capítulo 11 - Processamento em Paralelo](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_11_PROCESSAMENTO_EM_PARALELO.ipynb)
32 | - [Capítulo 12 - Google Trends E Mercado Financeiro](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_12_GOOGLE_TRENDS_E_MERCADO_FINANCEIRO.ipynb)
33 | - [Capítulo 13 - Inteligência Artificial No Google](https://github.com/GustavoRosso/PythonEMercadoFinanceiro/blob/main/CAP%C3%8DTULO_13_INTELIG%C3%8ANCIA_ARTIFICIAL_NO_GOOGLE.ipynb)
34 |
35 | ## Como Usar
36 |
37 | Para acessar os exemplos e exercícios resolvidos de cada capítulo, basta navegar nas pastas correspondentes.
38 |
39 | ## Contribuição
40 |
41 | Se você gostaria de contribuir para este repositório, sinta-se à vontade para criar problemas (issues) ou enviar pull requests com melhorias, correções ou novos exemplos.
42 |
43 | ## Nota de Responsabilidade
44 | Os códigos fornecidos aqui são para fins educacionais e de aprendizado. Embora eu tenha me esforçado para garantir que as soluções dos exercícios sejam precisas e eficazes, não posso garantir a sua correção em todas as situações. Portanto, recomenda-se usar esses códigos como referência e como ponto de partida para suas próprias explorações e projetos.
45 |
--------------------------------------------------------------------------------