-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5154 from marcoatrs/main
Reto #28 - Python
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Retos/Reto #28 - EXPRESIÓN MATEMÁTICA [Media]/python/marcoatrs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
signos_permitidos = "0123456789+-/*% " | ||
parejas_invalidas = ["*/", "/*", "%/", "/%", "*%", "%*", "%%", "+/", "-/"] | ||
|
||
|
||
def expresion_matematica(expresion: str) -> bool: | ||
# Caracter invalido | ||
for c in expresion: | ||
if c not in signos_permitidos: | ||
return False | ||
# Signos dobles | ||
expresion = expresion.replace(" ", "") | ||
for par in parejas_invalidas: | ||
if par in expresion: | ||
return False | ||
return True | ||
|
||
print(expresion_matematica("2 + 4")) | ||
print(expresion_matematica("2 + /4")) | ||
print(expresion_matematica("2 +y 4")) |