tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
16
Task/Roman-numerals-Encode/Python/roman-numerals-encode-2.py
Normal file
16
Task/Roman-numerals-Encode/Python/roman-numerals-encode-2.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
romanDgts= 'ivxlcdmVXLCDM_'
|
||||
|
||||
def ToRoman(num):
|
||||
namoR = ''
|
||||
if num >=4000000:
|
||||
print 'Too Big -'
|
||||
return '-----'
|
||||
for rdix in range(0, len(romanDgts), 2):
|
||||
if num==0: break
|
||||
num,r = divmod(num,10)
|
||||
v,r = divmod(r, 5)
|
||||
if r==4:
|
||||
namoR += romanDgts[rdix+1+v] + romanDgts[rdix]
|
||||
else:
|
||||
namoR += r*romanDgts[rdix] + (romanDgts[rdix+1] if(v==1) else '')
|
||||
return namoR[-1::-1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue