pytudes._2021.coderbyte.string_challenge__mediumο
https://coderbyte.com/information/String%20Expression
- Description:
For this challenge you will convert a string of written numbers to an
actual number.
Module Contentsο
Functionsο
|
Returns the evaluation of the arithmetic expression in a given string |
- pytudes._2021.coderbyte.string_challenge__medium.StringChallenge(strParam)[source]ο
Returns the evaluation of the arithmetic expression in a given string
- Args:
- strParam:
the input string containing the given arithmetic expression. Concretely, strParam contains the written out version of the numbers 0-9 and the words βminusβ or βplusβ.
- Returns:
The string representation of the arithmetic evaluation of strParam using the written out version of the numbers 0-9. If a negative number was produced, the number is prefixed by the word βnegativeβ.
- Examples:
>>> # 10 + 8 => >>> StringChallenge("onezeropluseight") 'oneeight' >>> # 18
>>> # 1 - 11 => >>> StringChallenge("oneminusoneone") 'negativeonezero' >>> # -10
>>> # 46 - 22 + 10 => >>> StringChallenge("foursixminustwotwoplusonezero") 'threefour' >>> # 34
>>> # Empty string (degenerate case) >>> StringChallenge("") 'zero' >>> # 0