Check if an input is a valid roman numeral

后端 未结 5 606
醉话见心
醉话见心 2021-01-14 10:46

I got a program that converts Roman numerals to integers and vice versa. My problem is that I don´t really know how to create a function that checks if the user input is a v

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-14 11:01

    Call romantoint after the for loop

     def checkIfRomanNumeral(numeral):
         """Controls that the userinput only contains valid roman numerals"""
         numeral = numeral.upper()
         validRomanNumerals = ["M", "D", "C", "L", "X", "V", "I"]
         for letters in numeral:
            if letters not in validRomanNumerals:
                print("Sorry that is not a valid roman numeral")
                return False
         romanToInt(numeral)
    

提交回复
热议问题