Skip to content

Commit

Permalink
Data
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchmd29 committed Mar 27, 2023
1 parent c5ff54c commit bade667
Showing 1 changed file with 328 additions and 0 deletions.
328 changes: 328 additions & 0 deletions 03 - Flujos de Control/mis_soluciones_homework_3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"1) Crear una variable que contenga un elemento del conjunto de números enteros y luego imprimir por pantalla si es mayor o menor a cero"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-10 El numero es menor que cero\n"
]
}
],
"source": [
"num = -10\n",
"if (num > 0):\n",
" print(num,' El numero es mayor a cero')\n",
"elif (num < 0):\n",
" print(num,' El numero es menor que cero')\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"2) Crear dos variables y un condicional que informe si son del mismo tipo de dato"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No son del mismo tipo\n"
]
}
],
"source": [
"var1 = '4'\n",
"var2 = 2\n",
"if (type (var1) == type (var2)):\n",
" print( var1, 'y', var2, ' son del mismo tipo')\n",
"else:\n",
" print ('No son del mismo tipo')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"3) Para los valores enteros del 1 al 20, imprimir por pantalla si es par o impar\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 Es impar\n",
"2 Es par\n",
"3 Es impar\n",
"4 Es par\n",
"5 Es impar\n",
"6 Es par\n",
"7 Es impar\n",
"8 Es par\n",
"9 Es impar\n",
"10 Es par\n",
"11 Es impar\n",
"12 Es par\n",
"13 Es impar\n",
"14 Es par\n",
"15 Es impar\n",
"16 Es par\n",
"17 Es impar\n",
"18 Es par\n",
"19 Es impar\n",
"20 Es par\n"
]
}
],
"source": [
"for n in range(1,21):\n",
" if (n % 2 == 0):\n",
" print (n, ' Es par')\n",
" else:\n",
" print(n, ' Es impar')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"4) En un ciclo for mostrar para los valores entre 0 y 5 el resultado de elevarlo a la potencia igual a 3"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 Elevado a la 3 es 0\n",
"1 Elevado a la 3 es 1\n",
"2 Elevado a la 3 es 8\n",
"3 Elevado a la 3 es 27\n",
"4 Elevado a la 3 es 64\n",
"5 Elevado a la 3 es 125\n"
]
}
],
"source": [
"for n in range(0,6):\n",
" print (n, ' Elevado a la 3 es ', (n ** 3))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"5) Crear una variable que contenga un número entero y realizar un ciclo for la misma cantidad de ciclos"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n"
]
}
],
"source": [
"var = 10\n",
"for var in range (var):\n",
" print (var)\n",
" var -= 1\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"6) Utilizar un ciclo while para realizar el factorial de un número guardado en una variable, sólo si la variable contiene un número entero mayor a 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"7) Crear un ciclo for dentro de un ciclo while"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"n=0\n",
"while (n > 3):\n",
" n += 1\n",
" for i in range (1,n):\n",
" print (i,' ciclo For')\n",
" print ('Ciclo while' , n)\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"n = 0\n",
"while(n < 5):\n",
" n += 1\n",
" for i in range(1,n):\n",
" print('Ciclo while nro ' + str(n))\n",
" print('Ciclo for nro ' + str(i))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"8) Crear un ciclo while dentro de un ciclo for"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"n = 5\n",
"for i in range (1,n):\n",
" while (n < 5):\n",
" n -= 1\n",
" print('Ciclo ', n)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
"n = 5\n",
"for i in range(1, n):\n",
" while(n < 5):\n",
" n -= 1\n",
" print('Ciclo while nro ' + str(n))\n",
" print('Ciclo for nro ' + str(i))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"9) Imprimir los números primos existentes entre 0 y 30"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"10) ¿Se puede mejorar el proceso del punto 9? Utilizar las sentencias break y/ó continue para tal fin"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "89a5003fa4d04edff07a126a2c6f2ee59ee1adb31e9fcd60b29f2b77c18232ea"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit bade667

Please sign in to comment.