Skip to content
Snippets Groups Projects
Commit 6b0bc5da authored by Jennifer Grisales Casadiegos's avatar Jennifer Grisales Casadiegos
Browse files

Ejercicio 3 sin comentar

parent ae0f3ea6
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: jennifer
Este programa entrega los números de una fila del
triángulo de Pascal.
"""
```
%% Output
'\n@author: jennifer\n\nEste programa entrega los números de una fila del\ntriángulo de Pascal.\n'
%% Cell type:markdown id: tags:
### Ejercicio 3: Amigos congueros
%% Cell type:markdown id: tags:
Entre en contacto con 10 estudiantes del curso de datos y 2 profesores o personal de soporte
de LaConga, uno del curso de datos y otro de afuera, y consulte su nombre completo, su
nombre de usuario en mattermost, edad, pais de origen, ciudad donde residen, su especialidad
científica, nombre del instituto en que estudian/laboran, y un hobbie o afición.
%% Cell type:markdown id: tags:
Cree un diccionario llamado “compas”, donde la llave sea el nombre de usuario en mattermost,
y si depliego el valor almacenado, por ejemplo en compas[“juan-pineda”], lo que obtengo es
a la vez otro diccionario, con las llaves “nombre”, “apellido”, “país”, “residencia”, “edad”,
“institución”, “hobbie”.
%% Cell type:markdown id: tags:
Cree una función que reciba como entrada el diccionario y un país de origen, y retorne las
informaciones completas de todas las personas de ese país, tabuladas en una forma fácil de
entender. -Busque una forma de calcular, a partir del diccionario, el promedio de edad de
todas las personas en él, y una forma de mostrar todas las instituciones (sin repetición)
%% Cell type:code id: tags:
``` python
d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}
compas = {"perezy": {"Nombre":"Yineth","Apellido":"Perez","Edad":29,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Voleibol y ficción", "Tipo": "Estudiante"},
"acerot": {"Nombre":"Tatiana","Apellido":"Acero","Edad":23,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Ver anime y disfrutar la naturaleza", "Tipo": "Estudiante"},
"omarasto":{"Nombre":"Omar","Apellido":"Asto","Edad":25,"País": "Perú",
"Ciudad": "Lima","Institución": "Universidad Nacional de Ingeniería", "Hobbie": "Leer periódico", "Tipo": "Estudiante"},
"carrilloj": {"Nombre":"Juan","Apellido":"Carrillo","Edad":25,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Videojuegos", "Tipo": "Estudiante"},
"ladinoj": {"Nombre":"JoseM","Apellido":"Ladino","Edad":24,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Skate, ciclismo, guitarra", "Tipo": "Estudiante"},
"martinezj": {"Nombre":"Jocabed","Apellido":"Martinez","Edad":22,"País": "Venezuela",
"Ciudad": "Caracas","Institución": "Universidad Central de Venezuela", "Hobbie": "Música", "Tipo": "Estudiante"},
"gomezc":{"Nombre":"Carla","Apellido":"Gomez","Edad":27,"País": "Venezuela",
"Ciudad": "Caracas","Institución": "Universidad Simón Bolivar", "Hobbie": "Bici, electrónica y la gastronomía", "Tipo": "Estudiante"},
"navasa":{"Nombre":"Alfonso","Apellido":"Navas","Edad":24,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Crossfit", "Tipo": "Estudiante"},
"vargass":{"Nombre":"Sasiri","Apellido":"Vargas","Edad":20,"País": "Colombia",
"Ciudad": "Cali","Institución": "Universidad del Valle", "Hobbie": "Danza y canto", "Tipo": "Estudiante"},
"sirias": {"Nombre":"Siria","Apellido":"Sadeddin","Edad":30,"País": "Venezuela",
"Ciudad": "Colombia","Institución": "Universidad Simón Bolivar", "Hobbie": "Data Science", "Tipo": "Estudiante"},
"teofilo": {"Nombre":"Teofilo","Apellido":"Vargas","Edad":54,"País": "Perú",
"Ciudad": "Lima","Institución": "Universidad Nacional Mayor de San Marcos", "Hobbie": "Wing Chun Kuen", "Tipo": "Profesor"},
"sirias": {"Nombre":"Siria","Apellido":"Sadeddin","Edad":30,"País": "Venezuela",
"Ciudad": "Colombia","Institución": "Universidad Simón Bolivar", "Hobbie": "Data Science", "Tipo": "Profesor"}}
"Ciudad": "Lima","Institución": "Universidad Nacional Mayor de San Marcos", "Hobbie": "Wing Chun Kuen", "Tipo": "Profesor"}
}
```
%% Cell type:code id: tags:
``` python
compas["teofilo"]["País"]
```
%% Output
'Perú'
%% Cell type:markdown id: tags:
# Promediar edades
%% Cell type:code id: tags:
``` python
import statistics as st
```
%% Cell type:code id: tags:
``` python
edades = []
for item in compas:
value = compas[item]["Edad"]
edades.append(value)
print(edades)
```
%% Output
[29, 23, 25, 25, 24, 22, 27, 24, 20, 30, 54]
%% Cell type:code id: tags:
``` python
st.mean(edades)
```
%% Output
27.545454545454547
%% Cell type:markdown id: tags:
# Mostrar las instituciones sin repetición
%% Cell type:code id: tags:
``` python
univer = []
for item in compas:
# print('Nombre:',compas[item]["Nombre"])
print('Pais:',compas[item]["País"])
value = compas[item]["Institución"]
univer.append(value)
print(univer)
```
%% Output
['Universidad Nacional de Colombia', 'Universidad Nacional de Colombia', 'Universidad Nacional de Ingeniería', 'Universidad Nacional de Colombia', 'Universidad Nacional de Colombia', 'Universidad Central de Venezuela', 'Universidad Simón Bolivar', 'Universidad Nacional de Colombia', 'Universidad del Valle', 'Universidad Simón Bolivar', 'Universidad Nacional Mayor de San Marcos']
%% Cell type:code id: tags:
``` python
#Eliminar elementos repetidos de la lista de Institutos
InstitutoT = []
for i in univer:
if i not in InstitutoT:
InstitutoT.append(i)
print(InstitutoT)
```
%% Output
Pais: Colombia
Pais: Colombia
Pais: Perú
Pais: Colombia
Pais: Colombia
Pais: Venezuela
Pais: Venezuela
Pais: Colombia
Pais: Colombia
Pais: Venezuela
Pais: Perú
['Universidad Nacional de Colombia', 'Universidad Nacional de Ingeniería', 'Universidad Central de Venezuela', 'Universidad Simón Bolivar', 'Universidad del Valle', 'Universidad Nacional Mayor de San Marcos']
%% Cell type:markdown id: tags:
# Tabular datos por país común
%% Cell type:code id: tags:
``` python
# Create a nested dictionary
courses={ 'bash': {'classes': 10, 'hours': 2, 'fee': 500},
'PHP': {'classes': 30, 'hours': 2, 'fee': 1500},
'Angular': {'classes': 10, 'hours': 2, 'fee': 1000}}
from tabulate import _table_formats, tabulate
```
%% Cell type:code id: tags:
``` python
# Print the keys and values of the dictionary
for course in courses:
print('Course Name:',course)
print('Total classes:',courses[course]['classes'])
print('Hours:',courses[course]['hours'])
print('Fee: $',courses[course]['fee'])
country = "Perú"
```
%% Cell type:code id: tags:
``` python
order = {}
keys = []
values = []
for item in compas:
if compas[item]["País"]== country:
keys.append(item)
print(keys)
```
%% Output
Course Name: bash
Total classes: 10
Hours: 2
Fee: $ 500
Course Name: PHP
Total classes: 30
Hours: 2
Fee: $ 1500
Course Name: Angular
Total classes: 10
Hours: 2
Fee: $ 1000
['omarasto', 'teofilo']
%% Cell type:code id: tags:
``` python
compas["perezy"]["País"]
```
%% Output
'Colombia'
%% Cell type:code id: tags:
``` python
Nombre = []
Apellido = []
Edad = []
Instituto = []
Hobbie = []
```
%% Cell type:code id: tags:
``` python
for word in keys:
element = compas[word]["Nombre"]
Nombre.append(element)
print(Nombre)
```
%% Output
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-18-c2695fec8d9c> in <module>
----> 1 print(compas["Apellido"])
['Omar', 'Teofilo']
%% Cell type:code id: tags:
KeyError: 'Apellido'
``` python
elements = ["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]
```
%% Cell type:code id: tags:
``` python
def congueros(dicci,country):
for item in compas:
# print('Nombre:',compas[item]["Nombre"])
print('Pais:',compas[item]["País"])
user = []
details = []
for word2 in keys:
for word in elements:
element = compas[word2][word]
details.append(element)
user.append(details)
details = []
print(user)
```
%% Output
[['Omar', 'Asto', 25, 'Universidad Nacional de Ingeniería', 'Leer periódico'], ['Teofilo', 'Vargas', 54, 'Universidad Nacional Mayor de San Marcos', 'Wing Chun Kuen']]
%% Cell type:code id: tags:
``` python
print(tabulate(user, headers=["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]))
```
%% Output
Nombre Apellido Edad Institución Hobbie
-------- ---------- ------ ---------------------------------------- --------------
Omar Asto 25 Universidad Nacional de Ingeniería Leer periódico
Teofilo Vargas 54 Universidad Nacional Mayor de San Marcos Wing Chun Kuen
%% Cell type:markdown id: tags:
## Crearé la función
%% Cell type:code id: tags:
``` python
newlist = []
for x in range(10):
innerlist = []
for y in range(10):
innerlist.append(y)
newlist.append(innerlist)
def congueros(dic,country):
from tabulate import _table_formats, tabulate
#
keys = []
values = []
for item in dic:
if dic[item]["País"]== country:
keys.append(item)
#
Nombre = []
Apellido = []
Edad = []
Instituto = []
Hobbie = []
#
for word in keys:
element = dic[word]["Nombre"]
Nombre.append(element)
#
elements = ["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]
#
user = []
details = []
for word2 in keys:
for word in elements:
element = dic[word2][word]
details.append(element)
user.append(details)
details = []
#
print(tabulate(user, headers=["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]))
```
print(newlist)
%% Cell type:code id: tags:
``` python
congueros(compas,"Perú")
```
%% Output
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
Nombre Apellido Edad Institución Hobbie
-------- ---------- ------ ---------------------------------------- --------------
Omar Asto 25 Universidad Nacional de Ingeniería Leer periódico
Teofilo Vargas 54 Universidad Nacional Mayor de San Marcos Wing Chun Kuen
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:code id: tags:
``` python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: jennifer
Este programa entrega los números de una fila del
triángulo de Pascal.
"""
```
%% Output
'\n@author: jennifer\n\nEste programa entrega los números de una fila del\ntriángulo de Pascal.\n'
%% Cell type:markdown id: tags:
### Ejercicio 3: Amigos congueros
%% Cell type:markdown id: tags:
Entre en contacto con 10 estudiantes del curso de datos y 2 profesores o personal de soporte
de LaConga, uno del curso de datos y otro de afuera, y consulte su nombre completo, su
nombre de usuario en mattermost, edad, pais de origen, ciudad donde residen, su especialidad
científica, nombre del instituto en que estudian/laboran, y un hobbie o afición.
%% Cell type:markdown id: tags:
Cree un diccionario llamado “compas”, donde la llave sea el nombre de usuario en mattermost,
y si depliego el valor almacenado, por ejemplo en compas[“juan-pineda”], lo que obtengo es
a la vez otro diccionario, con las llaves “nombre”, “apellido”, “país”, “residencia”, “edad”,
“institución”, “hobbie”.
%% Cell type:markdown id: tags:
Cree una función que reciba como entrada el diccionario y un país de origen, y retorne las
informaciones completas de todas las personas de ese país, tabuladas en una forma fácil de
entender. -Busque una forma de calcular, a partir del diccionario, el promedio de edad de
todas las personas en él, y una forma de mostrar todas las instituciones (sin repetición)
%% Cell type:code id: tags:
``` python
d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}
compas = {"perezy": {"Nombre":"Yineth","Apellido":"Perez","Edad":29,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Voleibol y ficción", "Tipo": "Estudiante"},
"acerot": {"Nombre":"Tatiana","Apellido":"Acero","Edad":23,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Ver anime y disfrutar la naturaleza", "Tipo": "Estudiante"},
"omarasto":{"Nombre":"Omar","Apellido":"Asto","Edad":25,"País": "Perú",
"Ciudad": "Lima","Institución": "Universidad Nacional de Ingeniería", "Hobbie": "Leer periódico", "Tipo": "Estudiante"},
"carrilloj": {"Nombre":"Juan","Apellido":"Carrillo","Edad":25,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Videojuegos", "Tipo": "Estudiante"},
"ladinoj": {"Nombre":"JoseM","Apellido":"Ladino","Edad":24,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Skate, ciclismo, guitarra", "Tipo": "Estudiante"},
"martinezj": {"Nombre":"Jocabed","Apellido":"Martinez","Edad":22,"País": "Venezuela",
"Ciudad": "Caracas","Institución": "Universidad Central de Venezuela", "Hobbie": "Música", "Tipo": "Estudiante"},
"gomezc":{"Nombre":"Carla","Apellido":"Gomez","Edad":27,"País": "Venezuela",
"Ciudad": "Caracas","Institución": "Universidad Simón Bolivar", "Hobbie": "Bici, electrónica y la gastronomía", "Tipo": "Estudiante"},
"navasa":{"Nombre":"Alfonso","Apellido":"Navas","Edad":24,"País": "Colombia",
"Ciudad": "Bogotá","Institución": "Universidad Nacional de Colombia", "Hobbie": "Crossfit", "Tipo": "Estudiante"},
"vargass":{"Nombre":"Sasiri","Apellido":"Vargas","Edad":20,"País": "Colombia",
"Ciudad": "Cali","Institución": "Universidad del Valle", "Hobbie": "Danza y canto", "Tipo": "Estudiante"},
"sirias": {"Nombre":"Siria","Apellido":"Sadeddin","Edad":30,"País": "Venezuela",
"Ciudad": "Colombia","Institución": "Universidad Simón Bolivar", "Hobbie": "Data Science", "Tipo": "Estudiante"},
"teofilo": {"Nombre":"Teofilo","Apellido":"Vargas","Edad":54,"País": "Perú",
"Ciudad": "Lima","Institución": "Universidad Nacional Mayor de San Marcos", "Hobbie": "Wing Chun Kuen", "Tipo": "Profesor"},
"sirias": {"Nombre":"Siria","Apellido":"Sadeddin","Edad":30,"País": "Venezuela",
"Ciudad": "Colombia","Institución": "Universidad Simón Bolivar", "Hobbie": "Data Science", "Tipo": "Profesor"}}
"Ciudad": "Lima","Institución": "Universidad Nacional Mayor de San Marcos", "Hobbie": "Wing Chun Kuen", "Tipo": "Profesor"}
}
```
%% Cell type:code id: tags:
``` python
compas["teofilo"]["País"]
```
%% Output
'Perú'
%% Cell type:markdown id: tags:
# Promediar edades
%% Cell type:code id: tags:
``` python
import statistics as st
```
%% Cell type:code id: tags:
``` python
edades = []
for item in compas:
value = compas[item]["Edad"]
edades.append(value)
print(edades)
```
%% Output
[29, 23, 25, 25, 24, 22, 27, 24, 20, 30, 54]
%% Cell type:code id: tags:
``` python
st.mean(edades)
```
%% Output
27.545454545454547
%% Cell type:markdown id: tags:
# Mostrar las instituciones sin repetición
%% Cell type:code id: tags:
``` python
univer = []
for item in compas:
# print('Nombre:',compas[item]["Nombre"])
print('Pais:',compas[item]["País"])
value = compas[item]["Institución"]
univer.append(value)
print(univer)
```
%% Output
['Universidad Nacional de Colombia', 'Universidad Nacional de Colombia', 'Universidad Nacional de Ingeniería', 'Universidad Nacional de Colombia', 'Universidad Nacional de Colombia', 'Universidad Central de Venezuela', 'Universidad Simón Bolivar', 'Universidad Nacional de Colombia', 'Universidad del Valle', 'Universidad Simón Bolivar', 'Universidad Nacional Mayor de San Marcos']
%% Cell type:code id: tags:
``` python
#Eliminar elementos repetidos de la lista de Institutos
InstitutoT = []
for i in univer:
if i not in InstitutoT:
InstitutoT.append(i)
print(InstitutoT)
```
%% Output
Pais: Colombia
Pais: Colombia
Pais: Perú
Pais: Colombia
Pais: Colombia
Pais: Venezuela
Pais: Venezuela
Pais: Colombia
Pais: Colombia
Pais: Venezuela
Pais: Perú
['Universidad Nacional de Colombia', 'Universidad Nacional de Ingeniería', 'Universidad Central de Venezuela', 'Universidad Simón Bolivar', 'Universidad del Valle', 'Universidad Nacional Mayor de San Marcos']
%% Cell type:markdown id: tags:
# Tabular datos por país común
%% Cell type:code id: tags:
``` python
# Create a nested dictionary
courses={ 'bash': {'classes': 10, 'hours': 2, 'fee': 500},
'PHP': {'classes': 30, 'hours': 2, 'fee': 1500},
'Angular': {'classes': 10, 'hours': 2, 'fee': 1000}}
from tabulate import _table_formats, tabulate
```
%% Cell type:code id: tags:
``` python
# Print the keys and values of the dictionary
for course in courses:
print('Course Name:',course)
print('Total classes:',courses[course]['classes'])
print('Hours:',courses[course]['hours'])
print('Fee: $',courses[course]['fee'])
country = "Perú"
```
%% Cell type:code id: tags:
``` python
order = {}
keys = []
values = []
for item in compas:
if compas[item]["País"]== country:
keys.append(item)
print(keys)
```
%% Output
Course Name: bash
Total classes: 10
Hours: 2
Fee: $ 500
Course Name: PHP
Total classes: 30
Hours: 2
Fee: $ 1500
Course Name: Angular
Total classes: 10
Hours: 2
Fee: $ 1000
['omarasto', 'teofilo']
%% Cell type:code id: tags:
``` python
compas["perezy"]["País"]
```
%% Output
'Colombia'
%% Cell type:code id: tags:
``` python
Nombre = []
Apellido = []
Edad = []
Instituto = []
Hobbie = []
```
%% Cell type:code id: tags:
``` python
for word in keys:
element = compas[word]["Nombre"]
Nombre.append(element)
print(Nombre)
```
%% Output
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-18-c2695fec8d9c> in <module>
----> 1 print(compas["Apellido"])
['Omar', 'Teofilo']
%% Cell type:code id: tags:
KeyError: 'Apellido'
``` python
elements = ["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]
```
%% Cell type:code id: tags:
``` python
def congueros(dicci,country):
for item in compas:
# print('Nombre:',compas[item]["Nombre"])
print('Pais:',compas[item]["País"])
user = []
details = []
for word2 in keys:
for word in elements:
element = compas[word2][word]
details.append(element)
user.append(details)
details = []
print(user)
```
%% Output
[['Omar', 'Asto', 25, 'Universidad Nacional de Ingeniería', 'Leer periódico'], ['Teofilo', 'Vargas', 54, 'Universidad Nacional Mayor de San Marcos', 'Wing Chun Kuen']]
%% Cell type:code id: tags:
``` python
print(tabulate(user, headers=["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]))
```
%% Output
Nombre Apellido Edad Institución Hobbie
-------- ---------- ------ ---------------------------------------- --------------
Omar Asto 25 Universidad Nacional de Ingeniería Leer periódico
Teofilo Vargas 54 Universidad Nacional Mayor de San Marcos Wing Chun Kuen
%% Cell type:markdown id: tags:
## Crearé la función
%% Cell type:code id: tags:
``` python
newlist = []
for x in range(10):
innerlist = []
for y in range(10):
innerlist.append(y)
newlist.append(innerlist)
def congueros(dic,country):
from tabulate import _table_formats, tabulate
#
keys = []
values = []
for item in dic:
if dic[item]["País"]== country:
keys.append(item)
#
Nombre = []
Apellido = []
Edad = []
Instituto = []
Hobbie = []
#
for word in keys:
element = dic[word]["Nombre"]
Nombre.append(element)
#
elements = ["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]
#
user = []
details = []
for word2 in keys:
for word in elements:
element = dic[word2][word]
details.append(element)
user.append(details)
details = []
#
print(tabulate(user, headers=["Nombre", "Apellido", "Edad", "Institución", "Hobbie"]))
```
print(newlist)
%% Cell type:code id: tags:
``` python
congueros(compas,"Perú")
```
%% Output
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
Nombre Apellido Edad Institución Hobbie
-------- ---------- ------ ---------------------------------------- --------------
Omar Asto 25 Universidad Nacional de Ingeniería Leer periódico
Teofilo Vargas 54 Universidad Nacional Mayor de San Marcos Wing Chun Kuen
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment