Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ejercicios-clase-02-datos
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carla Elena Gomez Alvarado
ejercicios-clase-02-datos
Commits
1ba0e9c1
Commit
1ba0e9c1
authored
4 years ago
by
Carla Elena Gomez Alvarado
Browse files
Options
Downloads
Patches
Plain Diff
Ejercicio 2 importado desde el Jupyter Hub
parent
0147b0c2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tarea2_Ejercicio_2_parte_a__1_.ipynb
+101
-0
101 additions, 0 deletions
Tarea2_Ejercicio_2_parte_a__1_.ipynb
with
101 additions
and
0 deletions
Tarea2_Ejercicio_2_parte_a__1_.ipynb
0 → 100644
+
101
−
0
View file @
1ba0e9c1
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ingrese un numero entero: 3\n"
]
}
],
"source": [
"#Solicitar al usuario ingreso de un número entero, siendo row una variable global\n",
"input_row= input('Ingrese un numero entero: ')\n",
"\n",
"# Try intenta hacer algo, si el numero ingresado no es un entero va al except\n",
"try:\n",
" row=int(input_row)\n",
"except:\n",
" print(\"El número ingresado no es entero\")\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Función Pascal_triangle \n",
" \n",
"def Pascal_triangle(row): \n",
" \n",
" for line in range(1, row + 1): \n",
" C = 1; \n",
" for i in range(1, line + 1): \n",
" # El primer elemento de cada fila del triangulo de pascal es 1\n",
" print(C, end = \" \"); \n",
" #Aplicación del binomio de Newton\n",
" C = int(C * (line - i) / i); \n",
" print(\"\"); \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 \n",
"1 1 \n",
"1 2 1 \n"
]
}
],
"source": [
"if type(row) == int: \n",
" \n",
" Pascal_triangle(row)\n",
" \n",
"else: \n",
" print(\"el número ingresado no es entero\")\n",
"\n",
" \n",
"\n",
" \n",
" \n",
" "
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:code id: tags:
```
python
#Solicitar al usuario ingreso de un número entero, siendo row una variable global
input_row
=
input
(
'
Ingrese un numero entero:
'
)
# Try intenta hacer algo, si el numero ingresado no es un entero va al except
try
:
row
=
int
(
input_row
)
except
:
print
(
"
El número ingresado no es entero
"
)
```
%% Output
Ingrese un numero entero: 3
%% Cell type:code id: tags:
```
python
# Función Pascal_triangle
def
Pascal_triangle
(
row
):
for
line
in
range
(
1
,
row
+
1
):
C
=
1
;
for
i
in
range
(
1
,
line
+
1
):
# El primer elemento de cada fila del triangulo de pascal es 1
print
(
C
,
end
=
"
"
);
#Aplicación del binomio de Newton
C
=
int
(
C
*
(
line
-
i
)
/
i
);
print
(
""
);
```
%% Cell type:code id: tags:
```
python
if
type
(
row
)
==
int
:
Pascal_triangle
(
row
)
else
:
print
(
"
el número ingresado no es entero
"
)
```
%% Output
1
1 1
1 2 1
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment