Skip to content

Instantly share code, notes, and snippets.

@se7enack
Last active July 19, 2024 19:33
Show Gist options
  • Select an option

  • Save se7enack/12bdf6068744ec2975e52bbe0ac5c99c to your computer and use it in GitHub Desktop.

Select an option

Save se7enack/12bdf6068744ec2975e52bbe0ac5c99c to your computer and use it in GitHub Desktop.
Roman Numeral and Int Conversion
#!/usr/bin/python3
import roman
errmsg = '\nOnly whole numbers or Roman Numerals between 1 and 3999 excepted\n'
number = input('Enter a number between 1 and 3999 in either Integer or Roman Numeral format> ')
if number.isalpha():
try:
print(roman.fromRoman(number.upper()))
except roman.InvalidRomanNumeralError:
print(errmsg)
else:
try:
number = int(number)
if number == 0 or number > 3999:
exit(0)
except:
print(errmsg)
exit(0)
try:
print(roman.toRoman(number))
except roman.OutOfRangeError:
print(errmsg)
except roman.NotIntegerError:
print(errmsg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment