Created
May 11, 2020 14:03
-
-
Save christiancost47/7e0949165a474e101a70bbe71609c001 to your computer and use it in GitHub Desktop.
Roman Number converter
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 Romanos(lista): | |
valores = { "0": 0, "I":1 , "V":5, "X":10, "L":50,"C":100,"M":1000 } | |
contador_geral = 0 | |
minimo = "0" | |
parcial = 0 | |
try: #BLOCO QUE PODE CAUSAR EXCEÇÃO | |
for algarismo in lista: | |
if (algarismo == minimo): | |
parcial += valores[algarismo] | |
else: | |
if (valores[algarismo]>valores[minimo]): | |
contador_geral -= parcial | |
else: | |
contador_geral += parcial | |
parcial = valores[algarismo] | |
minimo = algarismo | |
contador_geral += parcial | |
return contador_geral | |
except KeyError: #BLOCO PARA TRATAR A EXCEÇÃO | |
print("Valor inválido!") | |
while True: | |
resposta = str(input("Deseja digitar um novo número romano [s/n]?: ")) | |
if (resposta == "s"): | |
algarismo = str(input("Digite um número romano: ")) | |
if (algarismo == ""): | |
break | |
print(Romanos(algarismo)) | |
if (resposta == "n"): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment