munio's picture
added app.py
54212a7
raw
history blame contribute delete
721 Bytes
import gradio as gr
def romanToInt(s):
"""
:type s: str
:rtype: int
"""
num = {
'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000
}
value = 0
i = 0
while i < len(s)-1:
if num[s[i]] < num[s[i+1]]:
value += num[s[i+1]] - num[s[i]]
i += 2
else:
value += num[s[i]]
i += 1
if i == len(s)-1:
value += num[s[i]]
return value
interface = gr.Interface(
fn=romanToInt,
inputs=gr.Textbox(label="Roman Number"),
outputs=gr.Number(label="Integer"),
title="Roman to Integer",
description="Please enter Roman numerals (I, V, X, L, C, D, M) in uppercase."
)
interface.launch()