Advertisement
dmemsm

Задача 8

Dec 15th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. inp = input()
  2. result = 0
  3. n = 0
  4. nprev = 0
  5.  
  6. while inp != ".":
  7.     if inp == "I":
  8.         n = 1
  9.     elif inp == "V":
  10.         n = 5
  11.     elif inp == "X":
  12.         n = 10
  13.     elif inp == "L":
  14.         n = 50
  15.     elif inp == "C":
  16.         n = 100
  17.     elif inp == "D":
  18.         n = 500
  19.     elif inp == "M":
  20.         n = 10000
  21.     else:
  22.         print("Invalid symbol")
  23.         break
  24.     result += n
  25.     if nprev < n:
  26.         result -= 2*nprev
  27.     nprev = n
  28.     inp = input()
  29.  
  30. if result != 0:
  31.     print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement