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

Python program to print and add numbers starting 1 onwards till the sum of them is less than 100

Below is the code snippet to print the sum of number from 1 to 100 in Python. Check the indents. #Declaring Variable  sum=0  #Now Running For Loop from 1 to 100   #range(0,n) take 0 and leave the last element 'n'  for i in range (1,101):  #Checking weather sum is less than 100 or not       while((sum+i)<100):           sum+=i           print(sum,'\n')           #Once Printed Sum Now Break The While Loop           break #End Of Program #END OF THE PROGRAM

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...

Australia Takes on Google's Online Advertising Dominance, Calls for Data Shakeout

ACCC said Google's dominance of online advertising was so entrenched that existing laws were insufficient to rein in any anticompetitive behaviour. Australia's antitrust watchdog said it wants the power to curb Google's use of Internet data to sell targeted advertisements, saying the Big Tech firm dominated the market to the point of harming publishers, advertisers, and consumers. The comments, in a report published Tuesday, set up another possible showdown between Australia and Google months after the Alphabet unit vowed to pull core services from the country over a new content licensing law. It may also spur along an anti-monopoly lawsuit reportedly being prepared by the US justice department accusing Google of using its market muscle to hobble advertising rivals. European regulators are also scrutinising Google's advertising business. Google Abused Android Dominance, Shows Indian Antitrust Probe Report In its "ad tech" report, which still must be con...