Sección 1. Capítulo 7
single
Challenge: Unpacking Tuple Elements
Desliza para mostrar el menú
Tarea
Desliza para comenzar a programar
Given a tuple of numbers, write a function that unpacks the first and last elements and returns their sum.
- Unpack the first and last elements from the
numberstuple. - Calculate and return the sum of the extracted first and last elements. If the tuple contains only one item, return that item added to itself.
- Use the extended iterable unpacking syntax
(first, *middle, last) = numbersto isolate the first and last elements from the tuple when it contains more than one item. - Replace the brackets (
___) in the code with your implementation.
Solución
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 1. Capítulo 7
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla