Last active
July 19, 2024 19:33
-
-
Save se7enack/12bdf6068744ec2975e52bbe0ac5c99c to your computer and use it in GitHub Desktop.
Roman Numeral and Int Conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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