-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (28 loc) · 831 Bytes
/
main.py
File metadata and controls
32 lines (28 loc) · 831 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
import time
tokens = []
special_chars = [" ", "+", "-", "*", "/", "(", ")"]
def tokenize(string_to_tokenize):
current_token = ""
for x in range(len(string_to_tokenize)):
if special_chars.__contains__(string_to_tokenize[x]):
tokens.append(current_token)
tokens.append(string_to_tokenize[x])
current_token = ""
else:
current_token += string_to_tokenize[x]
tokens.append(current_token)
print_result()
def print_result():
string = ""
for y in range(len(tokens)):
string += tokens[y]
print(str(eval(string)))
tokens.clear()
while True:
time.sleep(0.5)
equation = input("Enter an equation: ")
print()
print("The answer is: ")
time.sleep(0.5)
tokenize(equation)
print()