top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Roman To Decimal


The simple idea is to calculate decimal numbers from roman so for that we have five steps process .The reason we are doing this is to get the idea of list and function to calculate the decimal number. Step 1. We defined a list of values consisting of roman letters and their significant values. roman = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000,

}

Step 2. Then we Calculate the length to know how long the value is as per list defined or is it exceeding it. for index in range(len(romannumbers) - 1):

Step 3. We checked the first symbol using the index value and followed by the next digit and it’s value. previous = romannumbers[index]

Step 4. Similarly we keep converting digit by digit checking the previous is always greater than next value. if previousNumber< nextNumber : result -= previousNumber else: result += previousNumber

Step 5. Hence we calculate the result as in whole and print it. result+=lastNumber

print(result)



 

For Example : MCDXLIX --> 1449

XX-->20

Click on the image to check full code




1 comment

Recent Posts

See All

1 comentario


Data Insight
Data Insight
19 sept 2021

Your first statement is contrary to your topic. Use the code snippet functionaliy to insert your code. And give an example of the use of your code.

Me gusta
bottom of page