Skip to content

Commit

Permalink
Reto mouredev#28 - Python
Browse files Browse the repository at this point in the history
  • Loading branch information
ycanas committed Aug 10, 2023
1 parent 460297d commit acd5147
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Retos/Reto #28 - EXPRESIÓN MATEMÁTICA [Media]/python/ycanas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def check(expression: str) -> bool:
componentes = expression.split(' ')

if len(componentes) >= 3 or len(componentes) % 2 == 0:
for index, value in enumerate(componentes):
if index % 2 == 0:
try:
float(value)
except:
return False

else:
if value not in ('+', '-', '*', '/', '%'):
return False

return True

return False


print(check("3 + 5"))
print(check("3 a 5"))
print(check("-3 + 5"))
print(check("- 3 + 5"))
print(check("-3 a 5"))
print(check("-3+5"))
print(check("3 + 5 - 1 / 4 % 8"))

0 comments on commit acd5147

Please sign in to comment.