Advertisement
1nikitas

Untitled

Mar 16th, 2022
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. Римские примеры
  2.  
  3. keys = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
  4. values = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
  5.  
  6.  
  7. def to_roman(n):
  8.     pointer = 0
  9.     result = ''
  10.     while n > 0:
  11.         while n >= keys[pointer]:
  12.             n -= keys[pointer]
  13.             result += values[pointer]
  14.         pointer += 1
  15.     return result
  16.  
  17.  
  18. def roman():
  19.     global one, two, three
  20.  
  21.     three = one + two
  22.     print(to_roman(one), "+", to_roman(two), "=", to_roman(three))
  23.  
  24. one = 5
  25. two = 4
  26. roman()
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement