Skip to content

Commit ff21ce2

Browse files
08
1 parent 665e162 commit ff21ce2

File tree

4 files changed

+340
-13
lines changed

4 files changed

+340
-13
lines changed

M08_clasesyOOP/Prep_Course_Homework_08-Resuelto.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
},
201201
{
202202
"cell_type": "code",
203-
"execution_count": 2,
203+
"execution_count": 1,
204204
"metadata": {},
205205
"outputs": [],
206206
"source": [
@@ -281,7 +281,7 @@
281281
},
282282
{
283283
"cell_type": "code",
284-
"execution_count": 18,
284+
"execution_count": 2,
285285
"metadata": {},
286286
"outputs": [],
287287
"source": [
@@ -670,7 +670,7 @@
670670
"name": "python",
671671
"nbconvert_exporter": "python",
672672
"pygments_lexer": "ipython3",
673-
"version": "3.10.11"
673+
"version": "3.12.0"
674674
}
675675
},
676676
"nbformat": 4,

M08_clasesyOOP/Prep_Course_Homework_08.ipynb

Lines changed: 267 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,92 @@
221221
},
222222
{
223223
"cell_type": "code",
224-
"execution_count": null,
224+
"execution_count": 5,
225225
"metadata": {},
226226
"outputs": [],
227-
"source": []
227+
"source": [
228+
"class Funciones:\n",
229+
"\n",
230+
" def __init__(self) -> None:\n",
231+
" pass\n",
232+
" \n",
233+
" def verificar_primo(self, numero):\n",
234+
" es_primo = True\n",
235+
" for divisor in range (2, numero):\n",
236+
" if numero % divisor == 0:\n",
237+
" es_primo = False\n",
238+
" break \n",
239+
" return es_primo\n",
240+
" \n",
241+
"\n",
242+
" def calcular_moda(self, lista):\n",
243+
"\n",
244+
" from collections import Counter \n",
245+
"\n",
246+
" conteo = Counter(lista)\n",
247+
" llave = max(conteo, key = conteo.get)\n",
248+
" valor = conteo[llave] \n",
249+
"\n",
250+
" return llave, valor\n",
251+
"\n",
252+
"\n",
253+
" def convertir_grados(self, valor, origen, destino):\n",
254+
" \n",
255+
" if origen == \"Celsius\":\n",
256+
" if destino == \"Celsius\":\n",
257+
" valor_destino = valor\n",
258+
" elif destino == \"Farenheit\":\n",
259+
" valor_destino = (valor * 9/5) + 32\n",
260+
" elif destino == \"Kelvin\":\n",
261+
" valor_destino = valor + 273.15\n",
262+
" else:\n",
263+
" print(\"Debe ingresar un destino correcto\")\n",
264+
" \n",
265+
" if origen == \"Farenheit\":\n",
266+
" if destino == \"Celsius\":\n",
267+
" valor_destino = (valor -32) * 5/9\n",
268+
" elif destino == \"Farenheit\":\n",
269+
" valor_destino = valor_destino \n",
270+
" elif destino == \"Kelvin\":\n",
271+
" valor_destino = ((valor - 32 )* 5/9) + 273.15\n",
272+
" else:\n",
273+
" print(\"Debe ingresar un destino correcto\") \n",
274+
" \n",
275+
" if origen == \"Kelvin\":\n",
276+
" if destino == \"Celsius\":\n",
277+
" valor_destino = valor - 273.15 \n",
278+
" elif destino == \"Farenheit\":\n",
279+
" valor_destino = ((valor - 273.15) * 9/5) + 32\n",
280+
" elif destino == \"Kelvin\":\n",
281+
" valor_destino = valor\n",
282+
" else:\n",
283+
" print(\"Debe ingresar un destino correcto\")\n",
284+
"\n",
285+
" return valor_destino\n",
286+
"\n",
287+
" def calcular_factorial (self,numero):\n",
288+
"\n",
289+
" if type(numero) != int:\n",
290+
" return \"La entrada debe ser in entero\"\n",
291+
" if numero <= 0:\n",
292+
" return \"La entrada debe ser un positivo\"\n",
293+
" if numero == 1:\n",
294+
" return 1\n",
295+
" numero = numero * self.calcular_factorial(numero - 1)\n",
296+
"\n",
297+
" return numero \n",
298+
"\n",
299+
" "
300+
]
301+
},
302+
{
303+
"cell_type": "code",
304+
"execution_count": 6,
305+
"metadata": {},
306+
"outputs": [],
307+
"source": [
308+
"f = Funciones()"
309+
]
228310
},
229311
{
230312
"attachments": {},
@@ -236,10 +318,83 @@
236318
},
237319
{
238320
"cell_type": "code",
239-
"execution_count": null,
321+
"execution_count": 7,
240322
"metadata": {},
241-
"outputs": [],
242-
"source": []
323+
"outputs": [
324+
{
325+
"data": {
326+
"text/plain": [
327+
"120"
328+
]
329+
},
330+
"execution_count": 7,
331+
"metadata": {},
332+
"output_type": "execute_result"
333+
}
334+
],
335+
"source": [
336+
"f.calcular_factorial(5)"
337+
]
338+
},
339+
{
340+
"cell_type": "code",
341+
"execution_count": 11,
342+
"metadata": {},
343+
"outputs": [
344+
{
345+
"data": {
346+
"text/plain": [
347+
"323.15"
348+
]
349+
},
350+
"execution_count": 11,
351+
"metadata": {},
352+
"output_type": "execute_result"
353+
}
354+
],
355+
"source": [
356+
"f.convertir_grados(50, \"Celsius\", \"Kelvin\")"
357+
]
358+
},
359+
{
360+
"cell_type": "code",
361+
"execution_count": 13,
362+
"metadata": {},
363+
"outputs": [
364+
{
365+
"data": {
366+
"text/plain": [
367+
"(1, 4)"
368+
]
369+
},
370+
"execution_count": 13,
371+
"metadata": {},
372+
"output_type": "execute_result"
373+
}
374+
],
375+
"source": [
376+
"f.calcular_moda([1,2,3,4,1,1,1])"
377+
]
378+
},
379+
{
380+
"cell_type": "code",
381+
"execution_count": 14,
382+
"metadata": {},
383+
"outputs": [
384+
{
385+
"data": {
386+
"text/plain": [
387+
"True"
388+
]
389+
},
390+
"execution_count": 14,
391+
"metadata": {},
392+
"output_type": "execute_result"
393+
}
394+
],
395+
"source": [
396+
"f.verificar_primo(11)"
397+
]
243398
},
244399
{
245400
"attachments": {},
@@ -251,10 +406,81 @@
251406
},
252407
{
253408
"cell_type": "code",
254-
"execution_count": null,
409+
"execution_count": 15,
255410
"metadata": {},
256411
"outputs": [],
257-
"source": []
412+
"source": [
413+
"class Funciones:\n",
414+
"\n",
415+
" def __init__(self, lista_numeros):\n",
416+
" self.lista = lista_numeros\n",
417+
" \n",
418+
" def verificar_primo(self, numero):\n",
419+
" es_primo = True\n",
420+
" for divisor in range (2, numero):\n",
421+
" if numero % divisor == 0:\n",
422+
" es_primo = False\n",
423+
" break \n",
424+
" return es_primo\n",
425+
" \n",
426+
"\n",
427+
" def calcular_moda(self, lista):\n",
428+
"\n",
429+
" from collections import Counter \n",
430+
"\n",
431+
" conteo = Counter(lista)\n",
432+
" llave = max(conteo, key = conteo.get)\n",
433+
" valor = conteo[llave] \n",
434+
"\n",
435+
" return llave, valor\n",
436+
"\n",
437+
"\n",
438+
" def convertir_grados(self, valor, origen, destino):\n",
439+
" \n",
440+
" if origen == \"Celsius\":\n",
441+
" if destino == \"Celsius\":\n",
442+
" valor_destino = valor\n",
443+
" elif destino == \"Farenheit\":\n",
444+
" valor_destino = (valor * 9/5) + 32\n",
445+
" elif destino == \"Kelvin\":\n",
446+
" valor_destino = valor + 273.15\n",
447+
" else:\n",
448+
" print(\"Debe ingresar un destino correcto\")\n",
449+
" \n",
450+
" if origen == \"Farenheit\":\n",
451+
" if destino == \"Celsius\":\n",
452+
" valor_destino = (valor -32) * 5/9\n",
453+
" elif destino == \"Farenheit\":\n",
454+
" valor_destino = valor_destino \n",
455+
" elif destino == \"Kelvin\":\n",
456+
" valor_destino = ((valor - 32 )* 5/9) + 273.15\n",
457+
" else:\n",
458+
" print(\"Debe ingresar un destino correcto\") \n",
459+
" \n",
460+
" if origen == \"Kelvin\":\n",
461+
" if destino == \"Celsius\":\n",
462+
" valor_destino = valor - 273.15 \n",
463+
" elif destino == \"Farenheit\":\n",
464+
" valor_destino = ((valor - 273.15) * 9/5) + 32\n",
465+
" elif destino == \"Kelvin\":\n",
466+
" valor_destino = valor\n",
467+
" else:\n",
468+
" print(\"Debe ingresar un destino correcto\")\n",
469+
"\n",
470+
" return valor_destino\n",
471+
"\n",
472+
" def calcular_factorial (self,numero):\n",
473+
"\n",
474+
" if type(numero) != int:\n",
475+
" return \"La entrada debe ser in entero\"\n",
476+
" if numero <= 0:\n",
477+
" return \"La entrada debe ser un positivo\"\n",
478+
" if numero == 1:\n",
479+
" return 1\n",
480+
" numero = numero * self.calcular_factorial(numero - 1)\n",
481+
"\n",
482+
" return numero "
483+
]
258484
},
259485
{
260486
"attachments": {},
@@ -266,10 +492,41 @@
266492
},
267493
{
268494
"cell_type": "code",
269-
"execution_count": null,
495+
"execution_count": 29,
496+
"metadata": {},
497+
"outputs": [],
498+
"source": [
499+
"from modulos_punto7 import*"
500+
]
501+
},
502+
{
503+
"cell_type": "code",
504+
"execution_count": 35,
270505
"metadata": {},
271506
"outputs": [],
272-
"source": []
507+
"source": [
508+
"f2 = Funciones([1,2,2,3,4,5,6,7,8,9,1,1,1,1,])"
509+
]
510+
},
511+
{
512+
"cell_type": "code",
513+
"execution_count": 36,
514+
"metadata": {},
515+
"outputs": [
516+
{
517+
"data": {
518+
"text/plain": [
519+
"120"
520+
]
521+
},
522+
"execution_count": 36,
523+
"metadata": {},
524+
"output_type": "execute_result"
525+
}
526+
],
527+
"source": [
528+
"f2.calcular_factorial(5)"
529+
]
273530
}
274531
],
275532
"metadata": {
@@ -291,7 +548,7 @@
291548
"name": "python",
292549
"nbconvert_exporter": "python",
293550
"pygments_lexer": "ipython3",
294-
"version": "3.11.6"
551+
"version": "3.12.0"
295552
}
296553
},
297554
"nbformat": 4,
Binary file not shown.

0 commit comments

Comments
 (0)