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

PUBG to Return in India ,Confirm Sources.

PUBG Mobile India has been given a green signal by the government Pubg Mobile has recently got the green light from the Indian telecommunication industry to start its operation in the country. Sources say the Indian government has given the go-ahead for PUBG Mobile’s comeback. The exact release date is still months away and has not been fixed, but the company is definitely coming back. TSM and Ghatak made the same kind of claims about the company. However, the government has made no official comment on such claims. GodNixon, aka Luv Sharma, a popular PUBG Mobile content creator, has now shared an update that the government has finally approved PUBG Mobile India. Nahi batane wala tha par apne londo ka pyaar rok nahi paya next two months are very good for pubg lovers and so many interesting news coming soon for TSM lovers ❤️ please don’t ask for date — Abhijeet Andhare (@GHATAK_official) March 27, 2021 |IN SHORT What is it?  A new PUBG Mobile game specifically for India Why was...