easy +10 pts

Match scientific notation

Write a regex that validates strings as scientific notation numbers.

Write a function `is_scientific_notation(s: str) -> bool` that returns `True` if the string `s` represents a valid scientific notation number, and `False` otherwise. A valid scientific notation number is defined as: - an optional sign (`+` or `-`), - followed by a decimal number (an integer part and optionally a fractional part), where the integer part is always present, - followed by the exponent marker `e` or `E`, - followed by an optional sign and an integer exponent (at least one digit). More precisely, the string must match the pattern: `[+-]?` then `(digits ( '.' digits? )? | '.' digits )` then `[eE]` then `[+-]?` then `digits`. Note that the decimal number must have digits – it cannot be just a dot. The exponent part is mandatory. The function should use regular expressions.

Constraints

- The input string `s` may be empty or contain up to 100 characters. - The function must use the `re` module (import is allowed). - No leading/trailing whitespace is allowed in the input. - Complexity: O(len(s)).

Example

>>> is_scientific_notation('1e10')
True
>>> is_scientific_notation('-1.2E-3')
True
>>> is_scientific_notation('.5e2')
True
>>> is_scientific_notation('1e')
False
>>> is_scientific_notation('1.2')
False
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `re.fullmatch` with a pattern that includes `^` and `$` anchors.
Remember to escape the dot in the decimal part if you use it literally, but you can use character classes too.
Break the pattern: optional sign, decimal part, exponent marker, optional sign, exponent digits.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.