diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-07-31 15:49:22 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-07-31 15:49:22 +0800 |
| commit | e7b6313261ef4541d4dcc303c46ef0d886649b70 (patch) | |
| tree | 8cff819a2036dd8d0172b6343b0a199d7b81721a /challenge-227/eric-cheung/python/ch-2.py | |
| parent | 4fda4a4a398e64921020704733556a2ec6dae78a (diff) | |
| parent | e511966ce2280dbedb2c916d9e6254708800639e (diff) | |
| download | perlweeklychallenge-club-e7b6313261ef4541d4dcc303c46ef0d886649b70.tar.gz perlweeklychallenge-club-e7b6313261ef4541d4dcc303c46ef0d886649b70.tar.bz2 perlweeklychallenge-club-e7b6313261ef4541d4dcc303c46ef0d886649b70.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-227/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-227/eric-cheung/python/ch-2.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/challenge-227/eric-cheung/python/ch-2.py b/challenge-227/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..ce59ffaa51 --- /dev/null +++ b/challenge-227/eric-cheung/python/ch-2.py @@ -0,0 +1,53 @@ +
+import roman
+
+nMaxLimit = 3999
+
+def GetRomanArithOper (strInput):
+
+ global nMaxLimit
+
+ arrElem = strInput.split()
+ nInt_01 = roman.fromRoman(arrElem[0])
+ strOperator = arrElem[1]
+ nInt_02 = roman.fromRoman(arrElem[2])
+
+ if strOperator == "+":
+ if nInt_01 + nInt_02 > nMaxLimit:
+ return "non potest"
+ return roman.toRoman(nInt_01 + nInt_02)
+
+ if strOperator == "-":
+ if nInt_01 > nInt_02:
+ return roman.toRoman(nInt_01 - nInt_02)
+ if nInt_01 == nInt_02:
+ return "nulla"
+ return "non potest"
+
+ if strOperator == "/":
+ if nInt_01 % nInt_02 == 0:
+ return roman.toRoman(int(nInt_01 / nInt_02))
+ return "non potest"
+
+ if strOperator == "*":
+ if nInt_01 * nInt_02 > nMaxLimit:
+ return "non potest"
+ return roman.toRoman(nInt_01 * nInt_02)
+
+ if strOperator == "**":
+ if nInt_01 ** nInt_02 > nMaxLimit:
+ return "non potest"
+ return roman.toRoman(nInt_01 ** nInt_02)
+
+
+## strGivenExpr = "IV + V"
+## strGivenExpr = "M - I"
+## strGivenExpr = "X / II"
+## strGivenExpr = "XI * VI"
+## strGivenExpr = "VII ** III"
+## strGivenExpr = "V - V"
+## strGivenExpr = "V / II"
+## strGivenExpr = "MMM + M"
+strGivenExpr = "V - X"
+
+print (GetRomanArithOper(strGivenExpr))
|
