Created
June 20, 2018 13:35
-
-
Save Ram-Aditya/db054e8913156b1513516a791c2e9b27 to your computer and use it in GitHub Desktop.
Week-6 Codebuddy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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