I'm writing a roman numeral to integers program and was testing some preexisting code with a few modifications I made.
list1={'I':1,'IV':4,'V':5,'IX':9,'X':10,'XL':40,'L':50,'XC':90,'C':100,'CD':400,'D':500,'CM':900,'M':1000}
def romanint(str):
result=0
count=0
while (count < len(str)):
value1 = list1[str[count]]
if (count + 1 < len(str)):
value2 = list1[str[count + 1]]
if (value1 >= value2):
result = result + value1
count = count + 1
else:
result = result + value2 - value1
count = count + 2
else:
result = result + value1
count = count + 1
return result
x=input("Please enter a Roman numeral: ")
print(romanint(x))
It works fine but I feel like there's a way to shorten it. I've tried to delete lines I've felt were unnecessary but errors always pop up. Is there a way to modify it or is it fine the way it is?