-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew Text Document.html
More file actions
40 lines (33 loc) · 1.18 KB
/
New Text Document.html
File metadata and controls
40 lines (33 loc) · 1.18 KB
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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<h1>Roman to Decimal-converter</h1>
<div id="plot"></div>
<py-script output="plot">
def encoder(num):
roman,s,decimal= ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"],"",[1000,900,500,400,100,90,50,40,10,9,5,4,1]
for i in range(13):
while num >= decimal[i]:
num -= decimal[i]
s += roman[i]
return s
def decoder(r):
k=r
if r=="":return "Don't leave the input blank"
roman,s= {"M":1000,"CM":900, "D":500, "CD":400, "C":100, "XC":90, "L":50, "XL":40, "X":10, "IX":9, "V":5, "IV":4, "I":1},0
while r!="":
if r[:2] in roman:a,r=r[:2],r[2:]
elif r[0] in roman:a,r=r[0],r[1:]
else: return "Enter proper Decimal/Roman number as input"
s+=roman[a]
return s if encoder(int(s))==k else "Not a valid Roman Numeral"
a=input()
try:print(encoder(int(a)))
except:print(decoder(a.upper()))
</py-script>
</body>
</html>