-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathapp.py
30 lines (24 loc) · 1.08 KB
/
app.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
from flask import Flask, render_template, request
app = Flask(__name__)
def convert(decimal_num):
roman = {1000:'M', 900:'CM', 500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9:'IX', 5:'V', 4:'IV', 1:'I'}
num_to_roman = ''
for i in roman.keys():
num_to_roman += roman[i]*(decimal_num//i)
decimal_num %= i
return num_to_roman
@app.route('/', methods=['POST', 'GET'])
def main_post():
if request.method == 'POST':
alpha = request.form['number']
if not alpha.isdecimal():
return render_template('index.html', developer_name='Rumeysa', not_valid=True)
number = int(alpha)
if not 0 < number < 4000:
return render_template('index.html', developer_name='Rumeysa', not_valid=True)
return render_template('result.html', number_decimal = number , number_roman= convert(number), developer_name='Rumeysa')
else:
return render_template('index.html', developer_name='Rumeysa', not_valid=False)
if __name__ == '__main__':
# app.run(debug=True)
app.run(host='0.0.0.0', port=80)