Write a program that prompts the user to enter a number within the range of 1 through 10.The program should display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the program should display an error message. The following table shows the Roman numerals for the numbers 1 through 10:
Code:
input_number=int(input('Enter any number between 1 to 10:')) #entering the input numbers
display="" #initialising display
if input_number<1 or input_number>10: #checking if else statement
display="\nE error. number must be between 1 to 10."
else:
#valid
display="\n the Roman numeral version of "
if input_number==1: #checking elif statement
display += format(input_number) + " is I" #assigning roman numbers to diplay
elif input_number==2:
display += format(input_number) + " is II"
elif input_number==3:
display += format(input_number) + " is III"
elif input_number==4:
display += format(input_number) + " is IV"
elif input_number==5:
display += format(input_number) + " is V"
elif input_number==6:
display += format(input_number) + " is VI"
elif input_number==7:
display += format(input_number) + " is VII"
elif input_number==8:
display += format(input_number) + " is VIII"
elif input_number==9:
display += format(input_number) + " is IX"
elif input_number==10:
display += format(input_number) + " is X"
print(display,'\n') #print display
Output:
Enter any number between 1 to 10:1
the Roman numeral version of 1 is I
Enter any number between 1 to 10:2
the Roman numeral version of 2 is II
Enter any number between 1 to 10:3
the Roman numeral version of 3 is III
Enter any number between 1 to 10:4
the Roman numeral version of 4 is IV
Enter any number between 1 to 10:5
the Roman numeral version of 5 is V
Enter any number between 1 to 10:6
the Roman numeral version of 6 is VI
Enter any number between 1 to 10:7
the Roman numeral version of 7 is VII
Enter any number between 1 to 10:8
the Roman numeral version of 8 is VIII
Enter any number between 1 to 10:9
the Roman numeral version of 9 is IX
Enter any number between 1 to 10:10
the Roman numeral version of 10 is X