forked from david-gary/CalculatorLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
46 lines (31 loc) · 833 Bytes
/
helpers.py
File metadata and controls
46 lines (31 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def is_a_number(token):
"""
Check if a token is a number, integer or float.
args:
- token: the token to check
returns:
- True if the token is a number, False otherwise
"""
try:
float(token)
return True
except ValueError:
return False
def is_unary_operator(token):
"""
Check if a token is a unary operator.
args:
- token: the token to check
returns:
- True if the token is a unary operator, False otherwise
"""
return token in ['sin', 'cos', 'tan', 'ln']
def is_binary_operator(token):
"""
Check if a token is a binary operator.
args:
- token: the token to check
returns:
- True if the token is a binary operator, False otherwise
"""
return token in ['+', '-', '*', '/']