Skip to content

Commit 800edf5

Browse files
authored
Merge pull request #26 from HighnessAtharva/patch-6
Update ValidatingRomanNumerals.py
2 parents 2a3b561 + d3aa3fd commit 800edf5

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

RegexandParsing/ValidatingRomanNumerals.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 3 April 2021
78
Problem : https://www.hackerrank.com/challenges/validate-a-roman-number/problem
89
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10+
11+
regex_pattern = r"^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
12+
1013
import re
11-
def my_func(s):
12-
s = s.upper()
13-
##res=re.match(r'^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$',s)
14-
res=re.search(r'^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$',s)
15-
if(s=="MMMM"):
16-
print "False"
17-
else:
18-
if res:
19-
print "True"
20-
else:
21-
print "False"
22-
my_func(raw_input())
14+
print(str(bool(re.match(regex_pattern, input()))))

0 commit comments

Comments
 (0)