Question

Create a function in python called “num_roman” that converts integers between 1 and 3999 into Roman...

Create a function in python called “num_roman” that converts integers between 1 and 3999 into Roman numerals. The input will be a scalar number and it should output a string that is the Roman numeral representation of the input number. The function should give a meaningful error message if the input is less than one. The function should truncate a fractional value to an integer. Different meaningful error messages should occur if you enter a value greater than 3999 or the value is not a scalar. If no input is entered it should return the Roman numeral for 2019. For legitimate values the function should build up a string as follows where x is the input: while (x>=1000) subtract 1000 from x and concatenate ‘M’ to the string if (x>=900) subtract 900 from x and concatenate ‘CM’ to the string if (x>=500) subtract 500 from x and concatenate ‘D’ to the string if (x>=400) subtract 400 from x and concatenate ‘CD’ to the string while (x>=100) subtract 100 from x and concatenate ‘C’ to the string if (x>=90) subtract 90 from x and concatenate ‘XC’ to the string if (x>=50) subtract 50 from x and concatenate ‘L’ to the string if (x>=40) subtract 40 from x and concatenate ‘XL’ to the string while (x>=10) subtract 10 from x and concatenate ‘X’ to the string if (x>=9) subtract 9 from x and concatenate ‘IX’ to the string if (x>=5) subtract 5 from x and concatenate ‘V’ to the string if (x>=4) subtract 4 from x and concatenate ‘IV’ to the string while (x>=1) subtract 1 from x and concatenate ‘I’ to the string

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Coding

Coding:

def int_to_Roman(num):#function for conversion to roman number here
    val = [
        1000, 900, 500, 400,
        100, 90, 50, 40,
        10, 9, 5, 4,
        1
        ]
    syb = [
            "M", "CM", "D", "CD",
            "C", "XC", "L", "XL",
            "X", "IX", "V", "IV",
            "I"
            ]#take symbol here to make it
    roman_num = ''
    i = 0
    while num > 0:
        for _ in range(num // val[i]):
            roman_num += syb[i]
            num -= val[i]
        i += 1
    return roman_num#return roman number here

while True:
    try:
        in_val=int(input("Please Enter integers between 1 and 3999 ::"))#input message here
        if(in_val>0 and in_val<4000):
            break
        else:
            print("\nPlease Make sure that value is between 1 and 3999\n")
    except:
        print("Please enter Correct value")
print("Roman Number is:"+str(int_to_Roman(in_val)))

output:

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
Create a function in python called “num_roman” that converts integers between 1 and 3999 into Roman...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its...

    Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its decimal number representation. Write a main program to test the function. Your function should have two arguments - the roman number as a string, and an error processing function. Write a helper function that will return the numeric value of each of the letters used in roman numbers. Then convert the string argument as follows look at the first two characters. If the first...

  • (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....

    (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits I 1 V 5 X 10 L 50 C 100 D 500 M 1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately....

  • Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete...

    Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete this program Save the flowchart as a PDF file Develop a C++ program, following the logic in your flowchart, to convert a series of whole number decimal values to their Roman equivalent. Develop a function that will accept a whole number value in the range 1-9999 and return a string containing the long-form Roman Numeral equivalent of the input value, consisting only of upper-case...

  • Lab 4: Java Fundamentals, Part IV In this assignment, you solve a conversion problem similar to...

    Lab 4: Java Fundamentals, Part IV In this assignment, you solve a conversion problem similar to Programming Challenge 1 of Chapter 3 of your text, page 184 (187 in Edition 5). Given one of the Roman numerals I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XIII, XIV, XV as an input your program must determine and display the corresponding decimal digit 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15....

  • Convert C++ language to PEP/8 assembly language

    Convert this C++ language to PEP/8 assembly language. #include <stdio.h> int main(void) {        int num, rem;     printf("Enter a number: ");     scanf("%d", &num);     printf("Roman numerals: ");             while(num != 0)     {         if (num >= 1000)       // 1000 - m         {            printf("m");            num -= 1000;         }         else if (num >= 900)   // 900 -  cm         {            printf("cm");            num -= 900;         }                 else if (num >= 500)   // 500 - d         {                       printf("d");            num -= 500;         }         else if (num >= 400)   // 400 -  cd         {            printf("cd");            num -= 400;         }         else if (num >= 100)   // 100 - c         {            printf("c");            num -= 100;                                }         else if (num >= 90)    // 90 - xc         {            printf("xc");            num -= 90;                                                       }         else if (num >= 50)    // 50 - l         {            printf("l");            num -= 50;                                                                              }         else if (num >= 40)    // 40 - xl         {            printf("xl");                       num -= 40;         }         else if (num >= 10)    // 10 - x         {            printf("x");            num -= 10;                    }         else if (num >= 9)     // 9 - ix         {            printf("ix");            num -= 9;                                  }         else if (num >= 5)     // 5 - v         {            printf("v");            num -= 5;                                              }         else if (num >= 4)     // 4 - iv         {            printf("iv");            num -= 4;                                                                     }         else if (num >= 1)     // 1 - i         {            printf("i");            num -= 1;                                                                                            }     }     return 0;}

  • C++ to Pep/8 assembly language

    Translate the following C++ program to Pep/8 assembly language.  Convert the given number into its roman numeral equivalent.class solution:   def int_to_Roman(self, num):       value = [            1000, 900, 500, 400,            100, 90, 50, 40,            10, 9, 5, 4,            1           ]       symbol = [            "M", "CM", "D", "CD",  ...

  • Write up a detailed solution to the problem: Design a program to convert a Roman numeral...

    Write up a detailed solution to the problem: Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number. Here are the “letters” you need to know: Symbol =   Value I   = 1 V =   5 X =   10 L =   50 C =   100 D =   500 M   =...

  • I'm having trouble getting a certain output with my program Here's my output: Please input a...

    I'm having trouble getting a certain output with my program Here's my output: Please input a value in Roman numeral or EXIT or quit: MM MM = 2000 Please input a value in Roman numeral or EXIT or quit: mxvi Illegal Characters. Please input a value in Roman numeral or EXIT or quit: MXVI MXVI = 969 Please input a value in Roman numeral or EXIT or quit: EXIT Illegal Characters. Here's my desired output: Please input a value in...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number...

    Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT