Skip to content

Commit a22cdc5

Browse files
committed
added solutions
1 parent d4d7661 commit a22cdc5

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

_episodes/02-datatypes.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,56 @@ import this
754754
> 3. Create two lists `l1 = [53, 16, 1, 86, 3, 33, 41, 76, 71, 4]` and `l2 = [30, 100, 94, 90, 17, 11, 39, 23, 90, 52]`. Use python to create a new list that contains only the odd numbers from both lists. The third list should look like this: `[53, 1, 3, 33, 41, 71, 17, 11, 39, 23]`.
755755
>
756756
> > ## Solutions
757-
> >
758-
> > The solutions will be posted in 4 days. Feel free to use the `#scripting_help` channel in Slack to discuss these exercises.
757+
> >
758+
> > (1) The index for character `l` is `a[6]`.
759+
> >
760+
> > ~~~
761+
> > a = 'Go Cyclones'
762+
> > b = a[6]
763+
> > print(b)
764+
> > ~~~
765+
> > {: .python}
766+
> >
767+
> > ~~~
768+
> > l
769+
> > ~~~
770+
> > {: .output}
771+
> >
772+
> > <br>
773+
> >
774+
> > (2) Use list indexing notation to reverse the string.
775+
> >
776+
> > ~~~
777+
> > print(a[::-1])
778+
> > ~~~
779+
> > {: .python}
780+
> >
781+
> > ~~~
782+
> > senolcyC oG
783+
> > ~~~
784+
> > {: .output}
785+
> >
786+
> > <br>
787+
> >
788+
> > (3) Use the modulo operator `%` to determine if the list element is divisible by `2`.
789+
> >
790+
> > ~~~
791+
> > l1 = [53, 16, 1, 86, 3, 33, 41, 76, 71, 4]
792+
> > l2 = [30, 100, 94, 90, 17, 11, 39, 23, 90, 52]
793+
> >
794+
> > for n in l1+l2:
795+
> > if n % 2 != 0:
796+
> > l3.append(n)
797+
> >
798+
> > print(l3)
799+
> > ~~~
800+
> > {: .python}
801+
> >
802+
> > ~~~
803+
> > [53, 1, 3, 33, 41, 71, 17, 11, 39, 23]
804+
> > ~~~
805+
> > {: .output}
806+
> >
807+
> >
759808
> {: .solution}
760809
{: .challenge}

0 commit comments

Comments
 (0)