-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clase9_10.html
1054 lines (954 loc) · 76.8 KB
/
Clase9_10.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clase 9-10: Funciones, diccionarios y condicionales — Introducción a python</title>
<link rel="stylesheet" href="_static/css/index.f658d18f9b420779cfdf24aa0a7e2d77.css">
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet"
href="_static/vendor/open-sans_all/1.44.1/index.css">
<link rel="stylesheet"
href="_static/vendor/lato_latin-ext/1.44.1/index.css">
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/sphinx-book-theme.e7340bb3dbd8dde6db86f25597f54a1b.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="preload" as="script" href="_static/js/index.d3f166471bb80abb5163.js">
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/togglebutton.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script >var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="_static/sphinx-book-theme.7d483ff0a819d6edff12ce0b1ead3928.js"></script>
<script async="async" src="https://unpkg.com/thebelab@latest/lib/index.js"></script>
<script >
const thebe_selector = ".thebe"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Clase 11-12: Introducción a los gráficos" href="Clase11_12.html" />
<link rel="prev" title="Clase 7-8" href="Clase7_8.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-xl">
<div class="row">
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
<div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="index.html">
<img src="_static/logo_fae.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">Introducción a python</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
</form>
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<ul class="nav sidenav_l1">
<li class="toctree-l1">
<a class="reference internal" href="intro.html">
Python para Ingeniería Comercial
</a>
</li>
</ul>
<ul class="current nav sidenav_l1">
<li class="toctree-l1">
<a class="reference internal" href="About_python.html">
Clase 2: About Python
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="clase3_4.html">
Clase 3-4: lo básico
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase5_6.html">
Clase 5-6: lo básico (continuación)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase5_6.html#actividad">
Actividad
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase7_8.html">
Clase 7-8
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Clase 9-10: Funciones, diccionarios y condicionales
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="#actividad-1">
Actividad 1
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase11_12.html">
Clase 11-12: Introducción a los gráficos
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase_13_14_a.html">
Clase 13: introducción a los datos
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase_13_14_b.html">
Clase 14: continuación con los datos
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase15.html">
Clase 15: gráficos
<em>
pro
</em>
con
<code class="docutils literal notranslate">
<span class="pre">
Plotly
</span>
</code>
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase15.html#actividad">
Actividad
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase17.html">
Clase 17: Introducción al análisis de texto (text mining)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase18.html">
Clase 18: Introducción al uso de clases
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase19.html">
Clase 19: Scipy y computación numérica
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="Clase20.html">
Clase 20: Regresiones
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
</div>
</div>
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
<div class="topbar container-xl fixed-top">
<div class="topbar-contents row">
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
<div class="col pl-md-4 topbar-main">
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
<i class="fas fa-bars"></i>
<i class="fas fa-arrow-left"></i>
<i class="fas fa-arrow-up"></i>
</button>
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
class="fas fa-download"></i></button>
<div class="dropdown-buttons">
<!-- ipynb file if we had a myst markdown file -->
<!-- Download raw file -->
<a class="dropdown-buttons" href="_sources/Clase9_10.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
data-placement="left">.ipynb</button></a>
<!-- Download PDF via print -->
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
onClick="window.print()" data-toggle="tooltip" data-placement="left">.pdf</button>
</div>
</div>
<!-- Source interaction buttons -->
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
aria-label="Connect with source repository"><i class="fab fa-github"></i></button>
<div class="dropdown-buttons sourcebuttons">
<a class="repository-button"
href="https://github.com/executablebooks/jupyter-book"><button type="button" class="btn btn-secondary topbarbtn"
data-toggle="tooltip" data-placement="left" title="Source repository"><i
class="fab fa-github"></i>repository</button></a>
<a class="issues-button"
href="https://github.com/executablebooks/jupyter-book/issues/new?title=Issue%20on%20page%20%2FClase9_10.html&body=Your%20issue%20content%20here."><button
type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
title="Open an issue"><i class="fas fa-lightbulb"></i>open issue</button></a>
</div>
</div>
<!-- Full screen (wrap in <a> to have style consistency -->
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
title="Fullscreen mode"><i
class="fas fa-expand"></i></button></a>
<!-- Launch buttons -->
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
aria-label="Launch interactive content"><i class="fas fa-rocket"></i></button>
<div class="dropdown-buttons">
<a class="binder-button" href="https://mybinder.org/v2/gh/executablebooks/jupyter-book/master?urlpath=tree/docs/Clase9_10.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Launch Binder" data-toggle="tooltip"
data-placement="left"><img class="binder-button-logo"
src="_static/images/logo_binder.svg"
alt="Interact on binder">Binder</button></a>
</div>
</div>
</div>
<!-- Table of contents -->
<div class="d-none d-md-block col-md-2 bd-toc show">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i>
Contents
</div>
<nav id="bd-toc-nav">
<ul class="nav section-nav flex-column">
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#">
Clase 9-10: Funciones, diccionarios y condicionales
</a>
</li>
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#actividad-1">
Actividad 1
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#instrucciones">
<strong>
Instrucciones:
</strong>
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="main-content" class="row">
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<div>
<div class="section" id="clase-9-10-funciones-diccionarios-y-condicionales">
<h1>Clase 9-10: Funciones, diccionarios y condicionales<a class="headerlink" href="#clase-9-10-funciones-diccionarios-y-condicionales" title="Permalink to this headline">¶</a></h1>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Importar librería</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</pre></div>
</div>
</div>
</div>
<p><strong>En esta classe vamos a ejercitar respondiendo las siguientes preguntas</strong></p>
<ol class="simple">
<li><p>Utilice las funciones de numpy <code class="docutils literal notranslate"><span class="pre">linspace()</span></code> y <code class="docutils literal notranslate"><span class="pre">arange()</span></code> para crear dos vectores entre 0-100. El primer vector tiene 1000 elementos entre el rango 0-100 y el segundo se encuentra separado por 1.5 (ejm: 0, 1.5, 3, …).</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Crear vector entre 0-100 con 1000 elementos</span>
<span class="n">vector1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"len(vector1):"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vector1</span><span class="p">))</span>
<span class="c1">#Crear vector entre 0-100 separados por 1.5</span>
<span class="n">vector2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"len(vector2):"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vector2</span><span class="p">))</span>
<span class="c1">#Vectores</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"vector1:"</span><span class="p">,</span> <span class="n">vector1</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"vector2:"</span><span class="p">,</span> <span class="n">vector2</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>len(vector1): 1000
len(vector2): 67
vector1: [0. 0.1001001 0.2002002 0.3003003 0.4004004 0.5005005 0.6006006
0.7007007 0.8008008 0.9009009]
vector2: [ 0. 1.5 3. 4.5 6. 7.5 9. 10.5 12. 13.5]
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Utilizando los vectores de 1. crear un <code class="docutils literal notranslate"><span class="pre">loop</span> <span class="pre">anidado</span></code> para calcular la multiplicación entre cada elemento de los vectores. Guarde los resultados en una lista.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Lista vacía</span>
<span class="n">lista</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1">#Loop</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">vector1</span><span class="p">:</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">vector2</span><span class="p">:</span>
<span class="n">lista</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="o">*</span><span class="n">j</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"len(lista):"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">lista</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"len(vector1)*len(vector2):"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vector1</span><span class="p">)</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">vector2</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>len(lista): 67000
len(vector1)*len(vector2): 67000
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Mediante un print() muestre la suma, el promedio, la mediana y la desviación estándar de la lista guardada en 2.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Suma</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"suma:"</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">lista</span><span class="p">))</span>
<span class="c1">#Promedio</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"promedio:"</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">lista</span><span class="p">))</span>
<span class="c1">#Mediana</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"mediana:"</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">lista</span><span class="p">))</span>
<span class="c1">#Desviación estandar</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Std:"</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">lista</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>suma: 165825000.0
promedio: 2475.0
mediana: 1839.3393393393394
Std: 2202.8088300489767
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Utilice la función input() para solicitar la cantidad de mascotas.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Solicitar input</span>
<span class="nb">input</span><span class="p">(</span><span class="s2">"¿Cuántas mascotas tiene?"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">StdinNotImplementedError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="o"><</span><span class="n">ipython</span><span class="o">-</span><span class="nb">input</span><span class="o">-</span><span class="mi">5</span><span class="o">-</span><span class="mf">1e0</span><span class="n">ab58c6baf</span><span class="o">></span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
<span class="g g-Whitespace"> </span><span class="mi">1</span> <span class="c1">#Solicitar input</span>
<span class="ne">----> </span><span class="mi">2</span> <span class="nb">input</span><span class="p">(</span><span class="s2">"¿Cuántas mascotas tiene?"</span><span class="p">)</span>
<span class="nn">~/miniconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py</span> in <span class="ni">raw_input</span><span class="nt">(self, prompt)</span>
<span class="g g-Whitespace"> </span><span class="mi">843</span> <span class="s2">"""</span>
<span class="g g-Whitespace"> </span><span class="mi">844</span><span class="s2"> if not self._allow_stdin:</span>
<span class="ne">--> </span><span class="mi">845</span><span class="s2"> raise StdinNotImplementedError(</span>
<span class="g g-Whitespace"> </span><span class="mi">846</span><span class="s2"> "raw_input was called, but this frontend does not support input requests."</span>
<span class="g g-Whitespace"> </span><span class="mi">847</span><span class="s2"> )</span>
<span class="ne">StdinNotImplementedError</span>: raw_input was called, but this frontend does not support input requests.
</pre></div>
</div>
</div>
</div>
<ol>
<li><p>Crear una rutina que permita las siguientes operaciones:</p>
<ol class="simple">
<li><p>Solicitar el número de mascotas (con input()), guardar en una variable.</p></li>
<li><p>Si el número de mascotas es cero: imprimir “No tiene mascotas.”</p></li>
<li><p>Si el número es entre 1-3: imprimir “Tiene entre 1-3 mascotas.”</p></li>
<li><p>Si el número es entre 4-6: imprimir “Tiene entre 4-6 mascotas.”</p></li>
<li><p>Si el número es mayor que 6: imprimir “Tiene más de 6 mascotas”.</p></li>
<li><p>Si el número es negativo: imprimir “No corresponde”.</p></li>
</ol>
<p>*Probar que su rutina cumple bien todas las condiciones. *</p>
</li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">mascotas</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">(</span><span class="s2">"¿Cuántas mascotas tiene?"</span><span class="p">))</span>
<span class="k">if</span> <span class="n">mascotas</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"No tiene mascotas"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">mascotas</span> <span class="o">></span><span class="mi">0</span> <span class="ow">and</span> <span class="n">mascotas</span> <span class="o"><=</span><span class="mi">3</span> <span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Tiene entre 1-3 mascotas"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">mascotas</span><span class="o">></span><span class="mi">3</span> <span class="ow">and</span> <span class="n">mascotas</span> <span class="o"><=</span><span class="mi">6</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Tiene entre 4-6 mascotas"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">mascotas</span><span class="o">></span><span class="mi">6</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Tiene mas de 6 mascotas"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">mascotas</span><span class="o"><</span><span class="mi">0</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"No corresponde"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"otro caso"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>¿Cuántas mascotas tiene? 0
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>No tiene mascotas
</pre></div>
</div>
</div>
</div>
<ol>
<li><p>Crear dos listas, una con estilo musical (blues, rock, rap, trap, pop) y otra con grupos (Nina Simone, Led Zeppelin, Makiza, Pablo Chill-e, Dua Lipa). Luego crear una función que tenga como input “estilo” y output “recomendacion”. La función debe permitir:</p>
<ol class="simple">
<li><p>Leer el input estilo y compararlo con la lista de estilo musical.</p></li>
<li><p>Utilizar if/elif/else para crear condiciones que recomiende música. Por ejemplo, si estilo es igual a Blues, recomendar Nina Simone.</p></li>
<li><p>Si el estilo no está en la lista de estilo musical, debe mostrar “No tenemos recomendación para su estilo musical”.</p></li>
<li><p>El output debe ser la recomendación.</p></li>
</ol>
<p><em>Evaluar si la función se ejecuta correctamente para cada estilo musical</em></p>
</li>
</ol>
<p><strong>Opción 1</strong></p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"blues"</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Nina Simone"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"rock"</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Led Zeppelin"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"rap"</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Makiza"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"trap"</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Pablo Chill-e"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"pop"</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Dua Lipa"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"No tenemos recomendación para su estilo musical."</span><span class="p">)</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="s1">'rap'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Makiza
</pre></div>
</div>
</div>
</div>
<p><strong>Opción 2</strong></p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"blues"</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"Nina Simone"</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"rock"</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"Led Zeppelin"</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"rap"</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"Makiza"</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"trap"</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"Pablo Chill-e"</span>
<span class="k">elif</span> <span class="n">estilo</span> <span class="o">==</span> <span class="s2">"pop"</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"Dua Lipa"</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación para su estilo musical."</span>
<span class="k">return</span> <span class="n">recomend</span>
<span class="c1">#Podemos guardar la recomendación en una variable</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="s1">'blues'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'Nina Simone'
</pre></div>
</div>
</div>
</div>
<p><strong>Opción 3</strong></p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">estilos</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"blues"</span><span class="p">,</span> <span class="s2">"rock"</span><span class="p">,</span> <span class="s2">"rap"</span><span class="p">,</span> <span class="s2">"trap"</span><span class="p">,</span> <span class="s2">"pop"</span><span class="p">]</span>
<span class="n">grupos</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Nina Simone"</span><span class="p">,</span> <span class="s2">"Led Zeppelin"</span><span class="p">,</span> <span class="s2">"Makiza"</span><span class="p">,</span> <span class="s2">"Pablo Chill-e"</span><span class="p">,</span> <span class="s2">"Dua Lipa"</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilos</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="k">return</span> <span class="n">recomend</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="s2">"rock"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'Led Zeppelin'
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Crear una función que permita evaluar hasta tres estilos musicales y entregue una lista con las recomendaciones. Por ejemplo, si le entrego una lista con [rock, rap, pop] me debe retornar [Led Zeppelin, Makiza, Dua Lipa]. Adicionalmente:</p>
<ul class="simple">
<li><p>Si le entrego una lista con 1 o 2 estilos musicales debe entregar 1 o 2 recomendaciones respectivamente.</p></li>
<li><p>Si le entrego una lista del tipo [trap, musica clasica] debe retornar la recomendación para trap [Pablo Chill-e].</p></li>
<li><p>Si le entrego una lista del tipo [musica clasica] debe retornar un mensaje “no tenemos recomendación para su estilo musical”.</p></li>
</ul>
</li>
</ol>
<p><strong>Pasos de la iteración</strong></p>
<ol class="simple">
<li><p>“blues”: igual a la pregunta 6</p></li>
<li><p>[“blues”]:</p>
<ul class="simple">
<li><p>si el lago del input == 1</p></li>
<li><p>iteramos sobre el total de estilos</p></li>
<li><p>si input (estilo) en la posición cero (primer elemento) es igual al valor de los estilos (sobre lo que estamos iterando)</p></li>
<li><p>entonces guardar el output como el grupo en la posición “i”.</p></li>
<li><p>cierre</p></li>
</ul>
</li>
<li><p>[“blues”, “rock”]:</p>
<ul class="simple">
<li><p>si el largo del input es igual a 2</p></li>
<li><p>creamos lista vacía para guardar las recomendaciones</p></li>
<li><p>iteramos sobre el total de elementos de estilos</p></li>
<li><p>Comparamos el primer elemento del input con los estilos ejm: si input[“blues”, rock”], comparamos “blues” con cada elemento de estilos.</p></li>
<li><p>Si son iguales, guardamos la recomendación (grupos[i]) en la lista, en caso contrario no hacemos nada.</p></li>
<li><p>Repetimos para el segundo elemento del input (“rock”).</p></li>
</ul>
</li>
<li><p>[“rock”, “blues”, “pop”]</p>
<ul class="simple">
<li><p>La lógica es la misma que en 3., sólo que ahora agregamos un tercer elemento y con ello una tercera condición.</p></li>
</ul>
</li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">estilos</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"blues"</span><span class="p">,</span> <span class="s2">"rock"</span><span class="p">,</span> <span class="s2">"rap"</span><span class="p">,</span> <span class="s2">"trap"</span><span class="p">,</span> <span class="s2">"pop"</span><span class="p">]</span>
<span class="n">grupos</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Nina Simone"</span><span class="p">,</span> <span class="s2">"Led Zeppelin"</span><span class="p">,</span> <span class="s2">"Makiza"</span><span class="p">,</span> <span class="s2">"Pablo Chill-e"</span><span class="p">,</span> <span class="s2">"Dua Lipa"</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="c1">#Entrada como texto: ejm "rock"</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="nb">str</span><span class="p">:</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilos</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="c1">#Entrada como lista ej ["rock"] o ["rock", "blues"]</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1">#1 estilo musical</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilos</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="c1">#2 estilos musicales</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilos</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="c1">#3 estilos musicales: </span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilos</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="n">estilos</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">grupos</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">return</span> <span class="n">recomend</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">gustos</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"rap"</span><span class="p">,</span> <span class="s2">"rock"</span><span class="p">,</span> <span class="s2">"blues"</span><span class="p">]</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="n">gustos</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>['Nina Simone', 'Led Zeppelin', 'Makiza']
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Crear una diccionario a partir de las dos listas donde la llave sea el estilo musical y el valor sea el grupo, ej: {‘rap’:’makiza’…}.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">musica_dic</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'blues'</span><span class="p">:</span><span class="s1">'Nina Simone'</span><span class="p">,</span> <span class="s1">'rock'</span><span class="p">:</span><span class="s1">'Led Zeppelin'</span><span class="p">,</span> <span class="s1">'rap'</span><span class="p">:</span><span class="s1">'Makiza'</span><span class="p">,</span> <span class="s1">'trap'</span><span class="p">:</span><span class="s1">'Pablo Chill-e'</span><span class="p">,</span> <span class="s1">'pop'</span><span class="p">:</span><span class="s1">'Dua Lipa'</span> <span class="p">}</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"diccionario:"</span><span class="p">,</span> <span class="n">musica_dic</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"llaves:"</span><span class="p">,</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"valores:"</span><span class="p">,</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"items:"</span><span class="p">,</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>diccionario: {'blues': 'Nina Simone', 'rock': 'Led Zeppelin', 'rap': 'Makiza', 'trap': 'Pablo Chill-e', 'pop': 'Dua Lipa'}
llaves: dict_keys(['blues', 'rock', 'rap', 'trap', 'pop'])
valores: dict_values(['Nina Simone', 'Led Zeppelin', 'Makiza', 'Pablo Chill-e', 'Dua Lipa'])
items: dict_items([('blues', 'Nina Simone'), ('rock', 'Led Zeppelin'), ('rap', 'Makiza'), ('trap', 'Pablo Chill-e'), ('pop', 'Dua Lipa')])
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Replicar la función 6. pero ahora utilizando diccionarios donde la función haga lo siguiente:</p>
<ol class="simple">
<li><p>Evaluar si el input (estilo) está en las <code class="docutils literal notranslate"><span class="pre">llaves</span></code> del diccionario.</p></li>
<li><p>Si el input está en llave del diccionario recomendar el grupo musical respectivo.</p></li>
<li><p>Si no está en la llave del diccionario retornar “No tenemos recomendación para su estilo musical”.</p></li>
</ol>
</li>
</ol>
<p><strong>Opción 1</strong></p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">musica_dic</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'blues'</span><span class="p">:</span><span class="s1">'Nina Simone'</span><span class="p">,</span> <span class="s1">'rock'</span><span class="p">:</span><span class="s1">'Led Zeppelin'</span><span class="p">,</span> <span class="s1">'rap'</span><span class="p">:</span><span class="s1">'Makiza'</span><span class="p">,</span> <span class="s1">'trap'</span><span class="p">:</span><span class="s1">'Pablo Chill-e'</span><span class="p">,</span> <span class="s1">'pop'</span><span class="p">:</span><span class="s1">'Dua Lipa'</span> <span class="p">}</span>
<span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">musica_dic</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="k">return</span> <span class="n">recomend</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="s2">"pop"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'Dua Lipa'
</pre></div>
</div>
</div>
</div>
<p><strong>Opción 2</strong></p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">v</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="k">return</span> <span class="n">recomend</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="s2">"rap"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'Makiza'
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Replicar la función de 7. utilizando diccionarios.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">musica_dic</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'blues'</span><span class="p">:</span><span class="s1">'Nina Simone'</span><span class="p">,</span> <span class="s1">'rock'</span><span class="p">:</span><span class="s1">'Led Zeppelin'</span><span class="p">,</span> <span class="s1">'rap'</span><span class="p">:</span><span class="s1">'Makiza'</span><span class="p">,</span> <span class="s1">'trap'</span><span class="p">:</span><span class="s1">'Pablo Chill-e'</span><span class="p">,</span> <span class="s1">'pop'</span><span class="p">:</span><span class="s1">'Dua Lipa'</span> <span class="p">}</span>
<span class="k">def</span> <span class="nf">recomendacion</span><span class="p">(</span><span class="n">estilo</span><span class="p">):</span>
<span class="c1">#Entrada como texto: ejm "rock"</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="nb">str</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">estilo</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">v</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="c1">#Entrada como lista ej ["rock"] o ["rock", "blues"]</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1">#1 estilo musical</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="n">v</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="s2">"No tenemos recomendación"</span>
<span class="c1">#2 estilos musicales</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="c1">#3 estilos musicales: </span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">estilo</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="n">recomend</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">musica_dic</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">estilo</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">:</span>
<span class="n">recomend</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">return</span> <span class="n">recomend</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">gustos</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"AA"</span><span class="p">]</span>
<span class="n">recomendacion</span><span class="p">(</span><span class="n">gustos</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>'No tenemos recomendación'
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Crear una función que entregue una edad como un valor aleatorio entre 15-65 años y educación como otro valor aleatorio entre 0-22, pero tiene que ser menor que la edad.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Caso 1: una sola persona</span>
<span class="k">def</span> <span class="nf">fun_edad_educ</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">,</span> <span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">):</span>
<span class="n">edad</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">)</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="k">if</span> <span class="n">edad</span><span class="o"><</span><span class="n">educ</span><span class="p">:</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="k">return</span> <span class="n">edad</span><span class="p">,</span> <span class="n">educ</span>
<span class="n">fun_edad_educ</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">22</span><span class="p">)</span> <span class="c1">#->que pasa si el if no es suficiente</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>(43, 7)
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Caso 1: una sola persona</span>
<span class="k">def</span> <span class="nf">fun_edad_educ</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">,</span> <span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">):</span>
<span class="n">edad</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">)</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="k">while</span> <span class="n">edad</span><span class="o"><</span><span class="n">educ</span><span class="p">:</span>
<span class="n">edad</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">)</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="k">return</span> <span class="n">edad</span><span class="p">,</span> <span class="n">educ</span>
<span class="n">fun_edad_educ</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>(62, 57)
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Caso 3: varias persona</span>
<span class="k">def</span> <span class="nf">fun_edad_educ</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">,</span> <span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">):</span>
<span class="n">edad_list</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">educ_list</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
<span class="n">edad</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">)</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="k">if</span> <span class="n">edad</span><span class="o"><</span><span class="n">educ</span><span class="p">:</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="n">edad_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">edad</span><span class="p">)</span>
<span class="n">educ_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">educ</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">edad_list</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">educ_list</span><span class="p">)</span>
<span class="n">edad_list</span><span class="p">,</span> <span class="n">educ_list</span> <span class="o">=</span> <span class="n">fun_edad_educ</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">22</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#Caso 4: varias persona</span>
<span class="k">def</span> <span class="nf">fun_edad_educ</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">,</span> <span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">):</span>
<span class="n">edad_list</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">educ_list</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
<span class="n">edad</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">)</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="k">while</span> <span class="n">edad</span><span class="o"><</span><span class="n">educ</span><span class="p">:</span>
<span class="n">edad</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">eda_in</span><span class="p">,</span> <span class="n">eda_end</span><span class="p">)</span>
<span class="n">educ</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">edu_in</span><span class="p">,</span> <span class="n">edu_end</span><span class="p">)</span>
<span class="n">edad_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">edad</span><span class="p">)</span>
<span class="n">educ_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">educ</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">edad_list</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">educ_list</span><span class="p">)</span>
<span class="n">edad_list</span><span class="p">,</span> <span class="n">educ_list</span> <span class="o">=</span> <span class="n">fun_edad_educ</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>(array([56, 58, 63, 58, 58, 54, 64, 57, 62, 61, 65, 64, 59, 62, 55, 54, 65,
65, 65, 54]),
array([51, 52, 60, 50, 52, 54, 64, 52, 53, 56, 60, 52, 55, 53, 50, 52, 54,
50, 58, 53]))
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Crear una función que calcule la experiencia como edad-educación</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">fun_exp</span><span class="p">(</span><span class="n">edad</span><span class="p">,</span> <span class="n">educ</span><span class="p">):</span>
<span class="k">return</span> <span class="n">edad</span><span class="o">-</span><span class="n">educ</span>
<span class="n">exp</span> <span class="o">=</span> <span class="n">fun_exp</span><span class="p">(</span><span class="n">edad_list</span><span class="p">,</span> <span class="n">educ_list</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<ol class="simple">
<li><p>Crear una función que calcule la estimación del ingreso según la ecuación de <code class="docutils literal notranslate"><span class="pre">Mincer</span></code>: <span class="math notranslate nohighlight">\(Ln(Y) = \beta_0 + \beta_1 S + \beta_2 Exp + \beta_3 Exp^2\)</span>
Donde:</p></li>
</ol>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(S\)</span>: años de educación</p></li>
<li><p><span class="math notranslate nohighlight">\(Exp\)</span>: experiencia</p></li>
<li><p><span class="math notranslate nohighlight">\(Exp^2\)</span>: experiencia al cuadrado</p></li>
</ul>
<p>Utilice: <span class="math notranslate nohighlight">\(\beta_0=9.7\)</span>, <span class="math notranslate nohighlight">\(\beta_1=0.14\)</span>, <span class="math notranslate nohighlight">\(\beta_2=0.07\)</span>, <span class="math notranslate nohighlight">\(\beta_3=-0.001\)</span></p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">mincer</span><span class="p">(</span><span class="n">S</span><span class="p">,</span> <span class="n">Exp</span><span class="p">):</span>
<span class="n">β0</span> <span class="o">=</span> <span class="mf">9.7</span>
<span class="n">β1</span> <span class="o">=</span> <span class="mf">0.14</span>
<span class="n">β2</span> <span class="o">=</span> <span class="mf">0.07</span>
<span class="n">β3</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.001</span>
<span class="k">return</span> <span class="n">β0</span> <span class="o">+</span> <span class="n">β1</span><span class="o">*</span><span class="n">S</span> <span class="o">+</span> <span class="n">β2</span><span class="o">*</span><span class="n">Exp</span> <span class="o">+</span> <span class="n">β3</span><span class="o">*</span><span class="n">Exp</span><span class="o">**</span><span class="mi">2</span>
<span class="n">ln_y</span> <span class="o">=</span> <span class="n">mincer</span><span class="p">(</span><span class="n">educ_list</span><span class="p">,</span> <span class="n">exp</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">educ_list</span><span class="p">,</span> <span class="n">ln_y</span><span class="p">,</span> <span class="s1">'o'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[<matplotlib.lines.Line2D at 0x7f8d284574c0>]
</pre></div>
</div>
<img alt="_images/Clase9_10_43_1.png" src="_images/Clase9_10_43_1.png" />
</div>
</div>
</div>
<div class="section" id="actividad-1">
<h1>Actividad 1<a class="headerlink" href="#actividad-1" title="Permalink to this headline">¶</a></h1>
<div class="section" id="instrucciones">
<h2><strong>Instrucciones:</strong><a class="headerlink" href="#instrucciones" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>Cada pregunta la debe responder en una celda diferente (en total 4 celdas de código).</p></li>
<li><p>Antes de cada celda de código debe ir un <code class="docutils literal notranslate"><span class="pre">markdown</span></code> que muestre la pregunta que está respondiendo.</p></li>
<li><p>En la celda de código debe agregar un breve comentario de qué está haciendo.</p></li>
<li><p>Mandar el archivo <strong>PDF</strong> al correo <a class="reference external" href="mailto:felix.ordonez%40usach.cl">felix<span>.</span>ordonez<span>@</span>usach<span>.</span>cl</a> con el asunto “Actividad 1”.</p></li>
<li><p>Fecha de entrega: antes de la clase del 09/11.</p></li>
<li><p><em>En caso que no respete las instrucciones se le descontará puntaje de la nota</em></p></li>
</ul>
<p><strong>Nombre:</strong></p>
<ol class="simple">
<li><p>Crear una función que entregue una edad como un valor aleatorio entre 15-65 años, educación como otro valor aleatorio entre 0-22 (tiene que ser menor que la edad) y sexo igual a una variable dicotómica (0 o 1) aleatoria.</p></li>
<li><p>Crear una función que calcule la experiencia como edad-educación</p></li>
<li><p>Crear una función que calcule la estimación del ingreso según la ecuación de Mincer: <span class="math notranslate nohighlight">\(Ln(y)=\beta_0+\beta_1S+\beta_2Exp+\beta_3Exp^2 + \beta_4 Sexo + \beta_5(Sexo*S)\)</span></p></li>
</ol>
<p>Donde:</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(S\)</span>: años de educación</p></li>
<li><p><span class="math notranslate nohighlight">\(Exp\)</span>: experiencia</p></li>
<li><p><span class="math notranslate nohighlight">\(Exp^2\)</span>: experiencia al cuadrado</p></li>
</ul>
<p>Utilice: <span class="math notranslate nohighlight">\(\beta_0=9.7\)</span>, <span class="math notranslate nohighlight">\(\beta_1=0.15\)</span>, <span class="math notranslate nohighlight">\(\beta_2=0.08\)</span>, <span class="math notranslate nohighlight">\(\beta_3=-0.0011\)</span>, <span class="math notranslate nohighlight">\(\beta_4=-0.15\)</span>, <span class="math notranslate nohighlight">\(\beta_5=-0.0136\)</span></p>
<ol class="simple">
<li><p>Relice el proceso en una iteración para N = 100 personas, guarde los resultados mediante un diccionario que la llave sea la persona (<span class="math notranslate nohighlight">\(n=1,\cdots,N\)</span>) y el valor sea una lista del tipo: [S, Exp, Exp2, Sexo, Sexo*S, Ln(y)].
<em>Muestre los resultados de su diccionario</em>.</p></li>
</ol>
</div>
</div>
<script type="text/x-thebe-config">