python programming help?

2009-02-23 11:48 pm
i need to make a program that converts a number into roman numbers that range from 1-9999.
this is what i did:
number=int(raw_input("Enter the number for convertion (<10,000)->"))
nthousand= number/1000
thousand= [" ", "M", "MM", "MMM", "MMMM"]
string1000=thousand(nthousand)
nhundred= number/100
hundred=[" ", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]
string100=hundred[nhundred]
nten= number/10
ten= [" ", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]
string10=ten[nten]
one= [" ", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]
string1=one
print "My number in Roman Numeral is->", string1000, string100, string10, string1

1) how can i do 5000, 6000,7000,8000,and 9000?
2) Python said i did something wrong but i couldnt' fix it. can someone please find out teh problem for me?

回答 (1)

2009-02-24 12:53 am
✔ 最佳答案
I don't know about numbers >= 5000, sorry.

But, I think Python told you that you asked for items beyond your arrays' sizes. After doing the integer division, for instance, nthousand = number/1000, you should perform a substraction: number= number -nthousand*1000 (or use an operator that gives the remainder of a division between integers).


收錄日期: 2021-04-25 13:41:55
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090223154806AAVS8aL

檢視 Wayback Machine 備份