Advertisement
ALEX-7320

Generador de números romanos

Feb 21st, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. base_num={1:"I",2:"II",3:"III",4:"IV",5:"V",
  2.           6:"VI",7:"VII",8:"VIII",9:"IX",
  3.  
  4.           10:"X",20:"XX",30:"XXX",40:"XL",50:"L",60:"LX",
  5.           70:"LXX",80:"LXXX",90:"XC",
  6.          
  7.           100:"C",200:"CC",300:"CCC",400:"CD",500:"D",
  8.           600:"DC",700:"DCC",800:"DCCC",900:"CM",
  9.  
  10.           1000:"M",2000:"MM",3000:"MMM",4000:"IV",5000:"V",
  11.           6000:"VI",7000:"VII",8000:"VIII",9000:"IX",
  12.  
  13.           10000:"X"}
  14.  
  15. print("*Generador de # Romanos [1 - 10.000]*")
  16. while True:
  17.     try:
  18.         num=int(input("Ingrese número: "))
  19.         if num>0 and num<=10000:break
  20.         else:print("Fuera de rango.")
  21.     except ValueError:print("Dato incorrecto.")
  22.  
  23. gen_num=[]
  24.  
  25. if(num in base_num):##valores del diccionario
  26.     gen_num.append(base_num[num])
  27.    
  28. else:
  29.     num=list(str(num))
  30.     for i in range(len(num),0,-1):
  31.         if(num[0]=="0"):
  32.             num.pop(0)
  33.         else:
  34.             gen_num.append(base_num[int(num[0])*int(str("1"+"0"*(i-1)))])
  35.             num.pop(0)
  36.  
  37. print("Equivalente: "+str("".join(gen_num)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement