From bee6425b51c9a03a7aaddf8d86d945e72be738ea Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 13 Nov 2026 09:46:33 +0000 Subject: [PATCH] Add a challenge for functions in intro chapter --- episodes/01-introduction.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/episodes/01-introduction.md b/episodes/01-introduction.md index d7f37268..ff721531 100644 --- a/episodes/01-introduction.md +++ b/episodes/01-introduction.md @@ -189,6 +189,35 @@ else: ::::::::::::::::::::::::::::::::::::::::::::::: +## Functions + +::::::::::::::::::::::::::::::::::::: challenge + +### 8\. Creating a function + +Using string slicing, write a function called `outer` that returns a string made up of the first and last characters of an input variable, so that a call to your function should give the following result: + +```python +print(outer('aluminium')) +print(outer("gold")) +``` +```output +am +gd +``` + +::::::::::::::: solution + +```python +def outer(input_string): + return input_string[0] + input_string[-1] +``` + +::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::::::::: + + ::::::::::::::::::::::::::::::::::::::::: callout ## Formatting Variables and Objects in Strings