[Tutor] roman to arabic
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Feb 27 00:47:41 CET 2012
On 26/02/2012 23:29, Sukhpreet Sdhu wrote:
> 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
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
I'm sorry but the code is so badly formatted via Thunderbird that it's
pretty much impossible to work out what you intend. Try resending with
the code correctly formatted. Also put print statements into the code
so that you can follow the flow and see what it's doing, then you'll be
able to make some progress yourself.
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list