[Tutor] roman to arabic

Sukhpreet Sdhu sukhpreet2294sidhu at ymail.com
Mon Feb 27 00:29:43 CET 2012


Hi
I just wrote python code to convert roman to arabic numerals, but its not working.
Can you just check where the problem is and way to correct that.
So here is my python code
import string
print "Welcome to the numeric conversion program"
print "Please enter command"
data=raw_input()
now = 0
previous = 0
total = 0
if data == "r":
    print "Enter roman numeric to convert in arabic"
    roman_numeric=string.swapcase(raw_input("Enter the Roman Numeral to convert to arabic"))
 if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" or "I"):                                                                                                 
     Length = len(roman_numeric) - 1
     i = roman_numeric[Length]
     if i == "M":
         now = 1000
         if i == "D":
             now = 500
             if i == "C":
                 now = 100
                 if i == "L":
                     now = 50
                     if i == "X":
                         now = 10
                         if i == "V":
                             now = 5
                             if i == "I":
                                 now = 1
                                 acc = now
                                 if (previous >= now):
                                     total += acc-prvious
                                     print "The total is",total
                                     if (previous <= now):
                                         total += acc-prevous
                                         print "The total is",total
                                         else :
                                             if data == "a" :
                                                 print "Arabic number to convert"

       thanks
sukhpreet sidhu                                                                 


More information about the Tutor mailing list