Following is the code for converting Roman Number to integer.
Click on "Read More".
This Code take input from user as Roman Number and then convert it into integer value.
Steps:
1) First we create a class names 'py_solution'
2)Then we define function inside the code.
3)Check Out The Code and if any query do comment we will get back to you
4)You can follow us on Tech Mayank on Instagram (@tech.mayank)
Click on "Read More".
This Code take input from user as Roman Number and then convert it into integer value.
Steps:
1) First we create a class names 'py_solution'
2)Then we define function inside the code.
3)Check Out The Code and if any query do comment we will get back to you
4)You can follow us on Tech Mayank on Instagram (@tech.mayank)
''' Author-Tech Mayank TechMayankS@gmail.com https://TechMaynk.blogspot.com ''' class py_solution: def roman(self, s): rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} int_val = 0 for i in range(len(s)): if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]: int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]] else: int_val += rom_val[s[i]] print(int_val) def main(): s=input('Enter the Roman Value:') ob=py_solution() ob.roman(s) if __name__=='__main__': main()
Comments
Post a Comment
Thanks for Your time . we appreciate your feedback. Comment here!