# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 4/13/2015 #Program Title: Chapter 4 Programming Excercise 1.py #(Roman Numerals) #Program Description: Promt the user for a number between 1-10, #check the input for the proper range and display the appropriate #roman numberal # ------------------------------------------------------------ #validates input range between 1 and 10 def inputRangeValidate(inputRange): if (inputRange <= 10 and inputRange >= 1 ): valid = True else: valid = False return valid # prompts user for a number between 1 and 10. def promptForNumber(strPrompt): userInput = int(raw_input(strPrompt + ": ")) print '{}' .format(userInput) return userInput #converts an integer to a Roman Numeral def integerToRomanNumeral(userInput): romanNumerals = ["I","II","III","IV","V","VI","VII","VIII","IX","X"] print '\nThe Roman Numeral of the integer {} is {} \n' .format(userInput, romanNumerals[userInput - 1]) #main driver function def main(): try: nonValidatedUserInput = promptForNumber("Please enter a number between 1 and 10") except (ValueError): print '\n\nInvalid input. You have entered a non integer. Please enter a number between 1 and 10' except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and then enter a number between 1 and 10' else: isValid = inputRangeValidate(nonValidatedUserInput) if (isValid): validInput = nonValidatedUserInput integerToRomanNumeral(validInput) else: print '\nInvalid input range. Please enter a number between 1 and 10' main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question