No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Playgrounds: Calcular la suma de todas las compras

30/44

Aportes 213

Preguntas 6

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

Buenas tardes! Yo realicé el código de la siguiente manera:

import my_functions

def get_total(orders):
  # Tu código aquí 👇
    
  totals = my_functions.get_totals(orders)
  Sum = my_functions.calc_total(totals)
  return Sum

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Yo lo hice sin necesidad de llamar a las funciones:

Me gusta mucho la dificultad de losplaygrounds OwO

import my_functions

def get_total(orders):
  
  ordenes = my_functions.get_totals(orders)

  
  suma_ordenes = my_functions.calc_total(ordenes)
  
  return suma_ordenes

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

from my_functions import * para no nombrar el archivo a la hora de usar las funciones

main:

from my_functions import get_totals, calc_total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_totals(orders)
result = calc_total(total)
print(result)

my_functions:

def get_totals(orders):
   return [order['total'] for order in orders]

def calc_total(totals):
   return sum(totals)

En mi caso yo hice el import directamente dentro de la funcion get_total

Pueden hacer el **import **dentro de la función para cumplir con la indicación de " # Tu código aquí 👇"

Mi solución usando las buenas prácticas del ENTRY POINT : if name == ‘main

import my_functions

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

def get_total(orders):
  totals = my_functions.get_totals(orders)
  return my_functions.calc_total(totals)

def run():
  total = get_total(orders)
  print(total)

if __name__ == '__main__':
  run()

Se complican mucho algunos

import my_functions

def get_total(orders):
  # Tu código aquí 👇
  return my_functions.calc_total(my_functions.get_totals(orders))

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Si no indicas el from, marca un error.

from my_functions import get_totals, calc_total

def get_total(orders):


  result = get_totals(orders)
  total_order = calc_total(result)
  return total_order

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Aqui la respuesta
Creo que no deberia ser tan lineal al momento de aceptar la respuesta. Intenté varios metodos los cuales cumplian con lo que pedia el reto y me la marcaba como mál.

import my_functions

def get_total(orders):
  # Tu código aquí 👇
  prices = my_functions.get_totals(orders)
  sum_prices = my_functions.calc_total(prices)
  return sum_prices

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

#Solucion en 3 lineas

ojo:

Esta no es la mejor solucion, sino la más resumida porque para el campo profesional necesitamos que otras personas entiendan nuestro codigo.

from my_functions import get_totals, calc_total

def get_total(orders):
  return calc_total(get_totals(orders))
  • A mi opinion esta esta mucho mejor en cuanto a lo esto se refiere:
def get_total(orders):
  total_items_arr = get_totals(orders)
  return calc_total(total_items_arr)

Una versión super resumida seria:

import my_functions

def get_total(orders):
  return my_functions.calc_total(my_functions.get_totals(orders))

Answer

import my_functions
def get_total(orders):
  # Tu código aquí 👇
  total=my_functions.get_totals(orders)
  
  return my_functions.calc_total(total)


def get_total(orders):
  # Tu código aquí 👇
 def get_total(orders):
  # Extraer el valor total de cada órden de compra
  totals = map(lambda x: x['total'], orders)
  
  # Sumar todos los valores totales y retornar el resultado
  return sum(totals)
  
orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Comparto mi solución:

import my_functions

def get_total(orders):
    obtain = my_functions.get_totals(orders)
    summary = my_functions.calc_total(obtain)
    return summary


orders = [
    {
        "customer_name": "Nicolas",
        "total": 100,
        "delivered": True,
    },
    {
        "customer_name": "Zulema",
        "total": 120,
        "delivered": False,
    },
    {
        "customer_name": "Santiago",
        "total": 20,
        "delivered": False,
    }
]

total = get_total(orders)
print(total)

Mi solución…

import my_functions #importamos el módulo de funciones

def get_total(orders):
  totales=my_functions.get_totals(orders)
  return my_functions.calc_total(totales)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Hola! Yo lo resolví así:

import my_functions
def get_total(orders):
  return my_functions.calc_total(my_functions.get_totals(orders))

yo solo escribí una lìnea de código aparte de las importaciones, que por cierto preferí importar específicamente solo para ser un poco mas explicito, analizando los módulos que importe me di cuenta que solamente tenia que dar a “calc_total” de input el output de “get_totals” al que le di de input el dataset “orders” siendo estrictos ni siquiera escribi codigo, solo conecte las entradas con las salidas

from my_functions import calc_total
from my_functions import get_totals
def get_total(orders):
  # Tu código aquí 👇
  return calc_total(get_totals(orders))

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Acá mi respuesta:

import my_functions

def get_total(orders):
  # Tu código aquí 👇
  totals = my_functions.get_totals(orders)
  
  return my_functions.calc_total(totals)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
import my_functions 

def get_total(orders):
  # Tu código aquí 👇
  total = my_functions.get_totals(orders)
  suma_total = my_functions.calc_total(total)
  return suma_total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

main

def get_total(orders):
  # Tu código aquí 👇
  from my_functions import get_totals, calc_total
  totales = get_totals(orders)
  sumas = calc_total(totales)

  return sumas

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

my_functions

def get_totals(orders):
   return [order['total'] for order in orders]

def calc_total(totals):
   return sum(totals)

Solo fue agregar dos lineas

Main

import my_functions  #Importar el modulo

def get_total(orders):
  result = my_functions.calc_total(my_functions.get_totals(orders)) #Hacer que calculara todo usando las dos funciones
  return result

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Aun asi no se si esta del todo bien

El playground no funciona

import my_functions
def get_total(orders):

Tu código aquí 👇

list_totales = my_functions.get_totals(orders)
total = my_functions.calc_total(list_totales)
return total

orders = [
{
“customer_name”: “Nicolas”,
“total”: 100,
“delivered”: True,
},
{
“customer_name”: “Zulema”,
“total”: 120,
“delivered”: False,
},
{
“customer_name”: “Santiago”,
“total”: 20,
“delivered”: False,
}
]

total = get_total(orders)
print(total)

Intenté resolver el reto de esta forma y aunque el resultado esté bien, me dice que está mal 😦

import my_functions


orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = my_functions.calc_total(my_functions.get_totals(orders))
print(total)
\#main.py def get\_total(orders): result= list(map(lambda item: item\['total'], orders)) return sum(result) \#archivo de ejecución: from main import get\_total orders = \[ { "customer\_name": "Nicolas", "total": 100, "delivered": True, }, { "customer\_name": "Zulema", "total": 120, "delivered": False, }, { "customer\_name": "Santiago", "total": 20, "delivered": False, } ] total = get\_total(orders) print(total)
Mi solución fue solo escribir la línea 1 y la línea 5: ```js from my_functions import get_totals, calc_total def get_total(orders): # Tu código aquí 👇 return calc_total(get_totals(orders)) ```
```python def get_total(orders): # Tu código aquí 👇 suma_total = sum(order["total"] for order in orders) return suma_total ```
1. import my\_functionsdef get\_total(orders):  # Tu código aquí 👇  totals = my\_functions.get\_totals(orders)  print(totals)  Sum = my\_functions.calc\_total(totals)  return Sum orders = \[  {    "customer\_name": "Nicolas",    "total": 100,    "delivered": True,  },  {    "customer\_name": "Zulema",    "total": 120,    "delivered": False,  },  {    "customer\_name": "Santiago",    "total": 20,    "delivered": False,  }] total = get\_total(orders)print(total)```js ```
```js import functools def get_total(orders): # Tu código aquí 👇 prices = list(map(lambda item: item['total'], orders)) result = functools.reduce(lambda conter, item: conter + item, prices) return result orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_total(orders) print(total) ```import functoolsdef get\_total(orders):  # Tu código aquí 👇  prices = list(map(lambda item: item\['total'], orders))  result = functools.reduce(lambda conter, item: conter + item, prices)  return result orders = \[  {    "customer\_name": "Nicolas",    "total": 100,    "delivered": True,  },  {    "customer\_name": "Zulema",    "total": 120,    "delivered": False,  },  {    "customer\_name": "Santiago",    "total": 20,    "delivered": False,  }] total = get\_total(orders)print(total)
```js def get_total(orders): # Tu código aquí 👇 from my_functions import get_totals, calc_total result = calc_total(get_totals(orders)) return result orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_total(orders) print(total) ```
```js https://platzi.com/new-home/clases/4260-python-funciones/57451-playgrounds-calcular-la-suma-de-todas-las-compras/ ```
![](https://platzi.com/new-home/clases/4260-python-funciones/57451-playgrounds-calcular-la-suma-de-todas-las-compras/) ```js ```
```js from my_functions import get_totals def get_total(orders): # Tu código aquí 👇 totals = get_totals(orders) return sum(totals) orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_total(orders) print(total) ```
Yo lo resolví así! ```js from my_functions import get_totals def get_total(orders): # Tu código aquí 👇 totals = get_totals(orders) return sum(totals) orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_total(orders) print(total) ```
Yo lo realice de una forma mas resumidaimport my\_functions ```js import my_functions def get_total(orders): # Tu código aquí 👇 return my_functions.calc_total(my_functions.get_totals(orders)) orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_total(orders) print(total) ```

excelente reto…

import my_functions
def get_total(orders):
    total=my_functions.get_totals(orders)
    return sum (total)
Para resolverlo yo lo hice así: ![](https://static.platzi.com/media/user_upload/image-9c2ba5b0-a01f-41a4-8542-68be59f3fd1f.jpg)El if que esta en la segunda función es para el caso de lista vacía, si se da la suma seria 0. Ya en el main solo importe las funciones dentro de la función. ![](https://static.platzi.com/media/user_upload/image-0ffcf853-e2e1-46f1-82e3-63eb6df8c72e.jpg)Para terminar solo ejecute las dos ultimas lineas: total = get\_total(orders) print(total)
![](https://static.platzi.com/media/user_upload/image-1dc1d2ae-51ed-48dd-9a69-24d03ac737cd.jpg)```js ```

Yo lo hice de esta manera

def get_total(orders):
  # Tu código aquí 👇
  import my_functions

  totals = my_functions.get_totals(orders)

  return my_functions.calc_total(totals)
  

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Me gusto este ejercicio cada vez siento que estoy mejorando.

from my_functions import get_totals, calc_total

def get_total(orders):
  # Tu código aquí 👇
  totals = get_totals(orders)
  orders = calc_total(totals)
  return orders

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total) 
Aunque el ejercicio dice que hay que usar los módulos, hice esta lógica, otra manera de resolver el ejercicio: ![](https://static.platzi.com/media/user_upload/msedge_3f07MfUDJb-dc15e2e7-28fa-4cc3-8db7-706b31e9491a.jpg)
![](https://static.platzi.com/media/user_upload/msedge_bB92fxxqe8-8a86fa67-8678-498a-8678-7de8166dac7d.jpg)
```js from my_functions import get_totals,calc_total def get_total(orders): total=calc_total(get_totals(orders)) return total ```
Hola encontré una forma más simplificada de resolver el desafío empleando las funtiontools mas específicamente REDUCE y una función lambda```python def get_totals(orders): return functools.reduce(lambda total, item: total + item['total'], orders, 0) #Modulo main.py from my_functions import get_totals orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_totals(orders) print(total). ```
Quiza no sea lo más optimo, porque considero q no se entiende tan bien `import my_functionsdef get_total(orders):  # Tu código aquí 👇  return my_functions.calc_total(my_functions.get_totals(orders))` `orders = [  {    "customer_name": "Nicolas",    "total": 100,    "delivered": True,  },  {    "customer_name": "Zulema",    "total": 120,    "delivered": False,  },  {    "customer_name": "Santiago",    "total": 20,    "delivered": False,  }]` `total = get_total(orders)print(total)`
```python import my_functions def get_total(orders): totals = my_functions.get_totals(orders) sumatoria = my_functions.calc_total(totals) return sumatoria orders = [ { "customer_name": "Nicolas", "total": 100, "delivered": True, }, { "customer_name": "Zulema", "total": 120, "delivered": False, }, { "customer_name": "Santiago", "total": 20, "delivered": False, } ] total = get_total(orders) print(total) ```import my\_functions def get\_total(orders):  totals = my\_functions.get\_totals(orders)  sumatoria = my\_functions.calc\_total(totals)  return sumatoria orders = \[  {    "customer\_name": "Nicolas",    "total": 100,    "delivered": True,  },  {    "customer\_name": "Zulema",    "total": 120,    "delivered": False,  },  {    "customer\_name": "Santiago",    "total": 20,    "delivered": False,  }] total = get\_total(orders)print(total)
```js import my_functions def get_total(orders): totals = my_functions.get_totals(orders) sumatoria = my_functions.calc_total(totals) return sumatoria ```import my\_functions def get\_total(orders):  totals = my\_functions.get\_totals(orders)  sumatoria = my\_functions.calc\_total(totals)  return sumatoria
Buen día, En mi caso modifique my\_functions.py main.py ```python import my_functions def get_total(orders): return my_functions.suma(orders) ```my\_functions.py ```js def suma(orders): prices = list(map(lambda item: item['total'], orders)) return sum(prices) ```
  1. Crea un archivo my_functions.py que contenga las funciones get_totals y calc_total. En este archivo, get_totals toma una lista de órdenes de compra y devuelve una lista con los totales de cada orden, mientras que calc_total toma una lista de totales y devuelve la suma de esos totales.
pythonCopy code
# my_functions.py

def get_totals(orders):
   return [order['total'] for order in orders]

def calc_total(totals):
   return sum(totals)

  1. En el archivo main.py, importa las funciones del archivo my_functions.py. Luego, en la función get_total, llama a get_totals para obtener una lista de totales y luego pasa esa lista a calc_total para obtener la suma total.
pythonCopy code
# main.py
from my_functions import get_totals, calc_total

def get_total(orders):
    totals = get_totals(orders)
    return calc_total(totals)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

  1. Ahora puedes ejecutar main.py, que utilizará las funciones definidas en my_functions.py para calcular y mostrar la suma total de todas las órdenes de compra.
![](https://static.platzi.com/media/user_upload/Screenshot%202023-09-27%20at%2020.42.49-3cc1c676-342f-460c-88b1-5decad1fbf44.jpg)
import my_functions
def get_total(orders):
  # Tu código aquí 👇
  return my_functions.calc_total(my_functions.get_totals(orders))

Esta es una posibilidad resumida

def get_total (orders): 
	import my_functions as mf
	return mf.calc_total(mf.get_totals(orders))
	
import my_functions
def get_total(orders):
  # Tu código aquí 👇
  totals = my_functions.get_totals(orders)
  total = my_functions.calc_total(totals)
  return total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
import my_functions
def get_total(orders):
  totals=my_functions.get_totals(orders)
  return my_functions.calc_total(totals)

import my_functions

def get_total(orders):
  # Tu código aquí 👇
  ordersList = my_functions.get_totals(orders)
  totalAmount = my_functions.calc_total(ordersList)
  totalAmount=int(totalAmount)
  return totalAmount

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]


total = get_total(orders)
print(total)

Me costó, tuve que acudir a las preguntas y más bien ahí leí una respuesta a mi duda.
Para hacer funcionar en Replit, he creado un archivo my_functions.py al que copié las funciones y funcionó correctamente.

from my_functions import get_totals, calc_total

def get_total(orders):
  orders = get_totals(orders)
  totals = calc_total(orders)
  return totals
orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Comparto mi solución con comentarios en el código.

  • Abajo

  • Más abajo

  • Aquí =>

Mi solucion

import my_functions as mf
def get_total(orders):
  # Tu código aquí 👇
  totals = mf.get_totals(orders)
  return mf.calc_total(totals) 

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
import my_functions

def get_total(orders):
  # Tu código aquí 👇

  totals = my_functions.get_totals(orders)
  total = my_functions.calc_total(totals)

  return total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)```

Good later, It’s my answer of this exercise:

from my_functions import get_totals, calc_total

def get_total(orders):
  totalm=get_totals(orders)
  return calc_total(totalm)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
from my_functions import get_totals, calc_total

def get_total(orders):
  # Tu código aquí 👇
  return calc_total(get_totals(orders))

Mi aporte es:

from my_functions import get_totals, calc_total

def get_total(orders):
  # Tu código aquí 👇
  result_get_totals = get_totals(orders)
  
  return calc_total(result_get_totals)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Buen di, aquí el mio.

<def get_total(orders):
  # Tu código aquí 👇
  total1 =0
  for i in orders:
    total1+= i["total"]
  return total1

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)> 

Podemos importar las funciones de un archivo en una sola línea de comando, para no llamar my_functions.etc…

from my_functions import get_totals, calc_total

def get_total(orders):
  # Tu código aquí 👇
  totals = get_totals(orders)
  total = calc_total(totals)
  return total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Mi respuesta

def get_total(orders):
  # Tu código aquí 👇
  import my_functions as lol
  answer = lol.calc_total(lol.get_totals(orders))
  return answer

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
# aqui lo importante es que tenemos una carpeta que serian nuestros paquetes que contiene modulos los cuales contienen las funciones

from paquetes.modulo_1 import obtener_totales
from paquetes.modulo_2 import calcular_total

def obtener_total(ordenes_de_compra):
  totales = obtener_totales(ordenes_de_compra)
  return calcular_total(totales)

ordenes_de_compra = [
  {
    "nombre_de_cliente": "Nicolas",
    "total": 100,
    "entregado": True,
  },
  {
    "nombre_de_cliente": "Zulema",
    "total": 120,
    "entregado": False,
  },
  {
    "nombre_de_cliente": "Santiago",
    "total": 20,
    "entregado": False,
  }
]

total = obtener_total(ordenes_de_compra)
print(total) # 240 y se pudo ejecutar como script desde python 30_ordenes_de_compra.py

# la mejor practica es usando name space (nombres reservados) y creamos __init.py__ por si se ejecuta desde versiones anterioes a la 3.3 y desde ahi importamos
import my_functions

def get_total(orders):
  # Tu código aquí 👇
  totals = my_functions.get_totals(orders)
  total = my_functions.calc_total(totals)
  return total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Este es mi aporte chicos.

básicamente hice que el result atrapara los datos de el diccionario (exactamente los valores), luego la variable result_2 los suma y se muestran . espero les sirva de guía

import my_functions
def get_total(orders):
  # Tu código aquí 👇
  result=my_functions.get_totals(orders)
  result_2=my_functions.calc_total(result)
  return result_2

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)


.
.
.
.
.
.
.

def get_total(orders):
  import my_functions

  total = my_functions.get_totals(orders)

  return sum(total)

De lo pocos que he hecho solo, bueno con ayuda de las notas de las clases, pero sin ver las soluciones de otros 5 + 5 = Yes!!!

Si el nombre del archivo es largo se puede usar un ‘alias’. Yo usé ‘my’

import my_functions as my
def get_total(orders):
  # Tu código aquí 👇
  totals = my.get_totals(orders)
  return my.calc_total(totals)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
import my_functions

def get_total(orders):
  # Tu código aquí 👇
  orders = my_functions.get_totals(orders)
  orders = my_functions.calc_total(orders)
  return orders
  

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
from my_functions import *

def get_total(orders):
  # Tu código aquí 👇
  return calc_total(get_totals(orders))
 

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
import my_functions

def get_total(orders):
  # Tu código aquí 👇
  list_total_orders = my_functions.get_totals(orders)
  total_orders = my_functions.calc_total(list_total_orders)
  return total_orders

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Mi solucion al playground 😄

from my_functions import get_totals, calc_total

def get_total(orders):
  # Tu código aquí 👇
  return calc_total(get_totals(orders))

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

import my_functions

def get_total(orders):

Tu código aquí 👇

get_orders = my_functions.get_totals(orders)
sum_orders = my_functions.calc_total(get_orders)
return sum_orders

Aquí como resolví el reto:

import my_functions
def get_total(orders):
  suma = my_functions.get_totals(orders)
  return my_functions.calc_total(suma)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Buen día
Esta es mi propuesta de solución.

import my_functions as mf

def get_total(orders):
  total = mf.calc_total(mf.get_totals(orders))
  return total

Esta fue mi solucion al ejercicio presentado, espero sirva de guia

import my_functions
def get_total(orders):
  # Tu código aquí 👇
  totales = my_functions.get_totals(orders)
  result = my_functions.calc_total(totales)
  return result

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Comparto por si les llega a servir!

import my_functions

def get_total(orders):
  # Tu código aquí 👇
  result = my_functions.get_totals(orders)
  suma = my_functions.calc_total(result)
  return suma

Esta es la solution que he implementado

rom my_functions import get_totals, calc_total


orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_totals(orders)
print(calc_total(total))

Gracias profe, el concepto en practica

al principio pensé usar reduce, pero cumpliendo con el reto 💪🐍

<import my_functions as mf

def get_total(orders):
  # Tu código aquí 👇
  totals = mf.get_totals(orders)
  return mf.calc_total(totals)

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)> 

Hola, les comparto mi Solución

import my_functions

def get_total(orders):

return my_functions.calc_total(my_functions.get_totals(orders))

orders = [
{
“customer_name”: “Nicolas”,
“total”: 100,
“delivered”: True,
},
{
“customer_name”: “Zulema”,
“total”: 120,
“delivered”: False,
},
{
“customer_name”: “Santiago”,
“total”: 20,
“delivered”: False,
}
]

total = get_total(orders)
print(total)

Gratamente sorprendido por la velocidad de respuesta de esta version del playground. Enhorabuena!

def get_total(orders):
  # Tu código aquí 👇
  import my_functions
  list_totales= my_functions.get_totals(orders)
  suma_total = my_functions.calc_total(list_totales)
  return suma_total

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
from my_functions import calc_total, get_totals

def get_total(orders):
  return calc_total(get_totals(orders))
def get_totals(orders):
	return [order['total'] for order in orders]

def calc_total(totals):
	import functools
	total = functools.reduce(lambda counter, item: counter + item, totals)
return total
  
import my_functions

def get_total(orders):
  price_list = my_functions.get_totals(orders)
  price_list_add = my_functions.calc_total(price_list)
  return price_list_add

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)
from my_functions import get_totals, calc_total

def get_total(orders):
  return calc_total(get_totals(orders))

orders = [
  {
    "customer_name": "Nicolas",
    "total": 100,
    "delivered": True,
  },
  {
    "customer_name": "Zulema",
    "total": 120,
    "delivered": False,
  },
  {
    "customer_name": "Santiago",
    "total": 20,
    "delivered": False,
  }
]

total = get_total(orders)
print(total)

Buenas, acá comparto mi solución por si le sirve a alguien. 😁 ![](

costó un poquito pero entendiendo bien el archivo my_function.py y ejecutando función por función se puede entender.

import my_functions

def get_total(orders):

Tu código aquí 👇

toral_2 = my_functions.get_totals(orders)
return my_functions.calc_total(total_2)

orders = [
{
“customer_name”: “Nicolas”,
“total”: 100,
“delivered”: True,
},
{
“customer_name”: “Zulema”,
“total”: 120,
“delivered”: False,
},
{
“customer_name”: “Santiago”,
“total”: 20,
“delivered”: False,
}
]

total = get_total(orders)
print(total)

undefined