In a forum I have found this nice function (done by Pixie) converting from Roman to Arabic numbers.
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="MCM"
print(decoder (a.upper))
I am a super newbie of Python, and I do not understand the statement
if r[:2]
in roman:a,r=r[:2],r[2:]
I know r[:2]
and others are string slicing. What I do not understand is the usage of the commas:
a,r=r[:2],r[2:]
looks as a tuple but why? Is it an assignment?