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
Instead of looping, you can convert both input and valid literals to sets and then substract them:
def checkIfRomanNumeral(numeral):
numeral = {c for c in numeral.upper()}
validRomanNumerals = {c for c in "MDCLXVI()"}
return not numeral - validRomanNumerals
Returns True
if numeral
is valid, False
otherwise. (Assuming that the empty string is valid)