2号文本 - 负数错误

时间:2017-02-19 22:06:03

标签: python python-2.7 negative-number

我正在编写一个我输入的代码(例如)1,我的输出是一个。

但是当我得到负数时,一切都出错了......

numbers = "zero one two three four five six seven eight nine".split()
numbers.extend("ten eleven twelve thirteen fourteen fifteen
sixteen".split())
numbers.extend("seventeen eighteen nineteen".split())
numbers.extend(tens if ones == "zero" else (tens + "-" + ones) 
    for tens in "twenty thirty forty fifty sixty seventy eighty     ninety".split()
    for ones in numbers[0:10])


 lol = int(raw_input ("Insert a number between 1 to 99! "))

while lol>=100:
 lol = int(raw_input ("Insert a number between 1 to 99! Not above 100!!!!!!! "))

  if lol <= -1:
        print "minus" + " " + numbers[lol]
else:
 print numbers[lol]

但是当我写了-7时,我减去了九十三......

有没有办法解决它?!

1 个答案:

答案 0 :(得分:0)

这是因为如果在列表中使用负数,则Python会向后计数。 前
    e=[1,2,3,4,5] e[-2] is equal to 4 你应该做的是使用math.abs()使它成为一个绝对值数字。