Skip to content

Commit

Permalink
Consider revising 'Strings to Numbers' exercise in episode 03
Browse files Browse the repository at this point in the history
Make it explicit that trying to recast types that don't make sense will throw an exception, with a demonstration.
Then include another nonsensical conversion for the actual exercise.
  • Loading branch information
biologyguy committed Aug 2, 2016
1 parent fb9ab55 commit 113b92c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions _episodes/03-types-conversion.md
Expand Up @@ -246,7 +246,7 @@ first is 2 and second is 5

> ## Strings to Numbers
>
> `float` will convert a string to a floating point number,
> Where reasonable, `float` will convert a string to a floating point number,
> and `int` will convert a floating point number to an integer:
>
> ~~~
Expand All @@ -261,7 +261,24 @@ first is 2 and second is 5
> ~~~
> {: .output}
>
> Given that,
> If the conversion doesn't make sense, however, an error message will occur
>
> ~~~
> print("string to float:", float("Hello world!"))
> ~~~
> {: .python}
>
> ~~~
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> <ipython-input-5-df3b790bf0a2> in <module>()
> ----> 1 print("string to float:", float("Hello world!"))
>
> ValueError: could not convert string to float: 'Hello world!'
> ~~~
> {: .error}
>
> Given this information,
> what do you expect this program to do?
> What does it actually do?
> Why do you think it does that?
Expand Down

0 comments on commit 113b92c

Please sign in to comment.