Skip to content

Instantly share code, notes, and snippets.

@Ram-Aditya
Created June 20, 2018 13:35
Show Gist options
  • Save Ram-Aditya/db054e8913156b1513516a791c2e9b27 to your computer and use it in GitHub Desktop.
Save Ram-Aditya/db054e8913156b1513516a791c2e9b27 to your computer and use it in GitHub Desktop.
Week-6 Codebuddy
def getVal(rom):
if (rom=="I"):
return 1
elif (rom=="V"):
return 5
elif (rom=="X"):
return 10
elif (rom=="L"):
return 50
elif (rom=="C"):
return 100
elif (rom=="D"):
return 500
elif (rom=="M"):
return 1000
rom=input()
tot=0
for i in range(len(rom)):
if i<=(len(rom)-2) and getVal(rom[i])<getVal(rom[i+1]):
tot-=getVal(rom[i])
else:
tot+=getVal(rom[i])
print(tot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment