numberchk=(int(input(\"Enter a Roman numeral or a Decimal numeral:\" )))
def int2roman(number):
numerals={1:\"I\", 4:\"IV\", 5:\"V\", 9: \"IX\", 10:\"X\", 40:\"XL\",
Use isinstance(numberchk, int)
instead, because int
is a type but numberchk
is an instance of that type.
Since int(input(...
always returns an integer as long as it can, you don't have to check it using if-else. To suppress error raising if input is not an integer, use try-except
as @poke mentioned.
You can also use a while-loop
and break
to request the user input repeatedly until you get an legal input:
while True:
try:
numberchk=int(input("Enter a Roman numeral or a Decimal numeral:" ))
break
except ValueError:
print('error')
print(int2roman(numberchk))