-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.py
43 lines (38 loc) · 1001 Bytes
/
interpreter.py
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
import math
from flask import Flask, request, render_template
app = Flask(__name__)
k = "\n"
def interpret(scrip):
n=""
if scrip == "":
n=""
for fizzbuzz in range(1,101):
if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:
n+="fizzbuzz"+k
continue
elif fizzbuzz % 3 == 0:
n+="fizz"+k
continue
elif fizzbuzz % 5 == 0:
n+="buzz"+k
continue
else:
n+=str(fizzbuzz)+k
return n
else:
a=[]
numbers = {str(x):x for x in range(10)}
numbers.update({'π':math.pi,'S':640,'F':256,'K':1000})
for x in scrip:
if x in numbers:
a.append(numbers[x])
return a
@app.route('/', methods =["GET", "POST"])
def gfg():
if request.method == "POST":
script = request.form.get('code')
return render_template('interpreter.html', output=interpret(script))
else:
return render_template("interpreter.html")
if __name__=='__main__':
app.run(debug=True)