Skip to main content

Convert Roman Number to Integer using Python.

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)
'''
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

Popular posts from this blog

Among Us: New hack ruins the fun as Crewmates start using vents

Among Us is being plagued by a new hack, which is ruining the fun for players. The new hack allows Crewmates to jump in and out of vents, further misleading the identity of the Impostor. As Among Us turned into one of the most popular online games to play in 2020, the flow of hackers and cheaters into the game has also seen a massive rise. This time, the hackers have brought forward an innovative touch to their malicious acts, allowing Crewmates in Among Us to use vents. The globally recognized game based on deception and manipulation enables Impostors in the game to use vents to travel across rooms with ease or even hide after committing the heinous crime of murder. However, venting has its own set of drawbacks as anyone caught going into or coming out of a vent can be easily deduced to be an Impostor. That being said, the hackers in Among Us have managed to hack the game in such a manner that allows Crewmates to use vents. New Among Us hack ruins the fun for many players As visi...

Machine Learning - Explained in easiest way

Machine Learning in Daily Life! When you hear the term Machine Learning, At once you imagine Robots and Some messy algorithms.  Well, Your Imagination is not wrong though. Let me get to the point. Machine Learning is not only about Robots, we see the application of ML in Our Daily Life, even we use it to get better performance or results! Surprised? So Hi, This is Mayank, An Machine Learning enthusiast, and Computer Science Student. In this blog, You will know the Machine Learning and the applications of it in our daily life. Well. Let me give you an example of it. Do you shop online.,  I believe you do. Did you notice, if you are buying a mobile phone then you get a suggestion to buy Mobile Cover too! Let us take another example of Google Photos, You have google photos on Your phone right? When you search some specific keywords like 'Garden', 'Memes', 'Screenshot'  Google Photos give you Images containing those specific visions. These all things possible to hap...

Facebook is testing ‘Green Screen’ editing tool for content creators

"Green Screen" will be available as an editing tool for the social media app whereas on Instagram it is available as an AR filter or effect." Facebook is testing a new feature for creators. The new “Green Screen” tool will allow users to add any video or image in the background of the Facebook Stories they create. This option is similar to the one available on Instagram already. However, it will be available as an editing tool for the social media app, whereas on Instagram it is available as an AR filter or effect. This tool was spotted by Mamun Billah via Social Media Today. As per the screenshot shared, the user can see the option in the stories section. The user can choose a photo or video from the Gallery section. When the user chooses the option, it is also labelled as “GREEN SCREEN by Instagram” at the bottom. Here’s the screenshot of the feature Green screen feature comes to facebook stories section! @MattNavarra pic.twitter.com/np9uMuQJaZ — Mamun Billah (@mamun...