Skip to content

Commit f61eed7

Browse files
authored
02-numpy.md: update 'Slicing Strings' challenge (#818)
1 parent a546e82 commit f61eed7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

_episodes/02-numpy.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,31 @@ which is the average inflammation per patient across all days.
546546
> > Creates a substring from index 1 up to (not including) the final index,
547547
> > effectively removing the first and last letters from 'oxygen'
548548
> {: .solution}
549+
>
550+
> How can we rewrite the slice for getting the last three characters of `element`,
551+
> so that it works even if we assign a different string to `element`?
552+
> Test your solution with the following strings: `carpentry`, `clone`, `hi`.
553+
>
554+
> > ## Solution
555+
> > ~~~
556+
> > element = 'oxygen'
557+
> > print('last three characters:', element[-3:])
558+
> > element = 'carpentry'
559+
> > print('last three characters:', element[-3:])
560+
> > element = 'clone'
561+
> > print('last three characters:', element[-3:])
562+
> > element = 'hi'
563+
> > print('last three characters:', element[-3:])
564+
> > ~~~
565+
> > {: .language-python}
566+
> > ~~~
567+
> > last three characters: gen
568+
> > last three characters: try
569+
> > last three characters: one
570+
> > last three characters: hi
571+
> > ~~~
572+
> > {: .output}
573+
> {: .solution}
549574
{: .challenge}
550575
551576
> ## Thin Slices

0 commit comments

Comments
 (0)