Python认为100小于50?

2024-10-01 02:25:38 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的代码:

stock_file  = open('Task_3_1.txt', "rt") #open file
stock_lines = stock_file.readlines() #convert items to list
total_buys = []
total_cost = []
done = 0
for o in range(0,(len(stock_lines)-1)): 
    edit = list(stock_lines[o])
    for m in range(1,2): #convert file to array
        edit.remove(edit[len(edit)-1])
    stock_lines[o] = ''.join(edit)
to_do = input("1. Find items that need to be restocked\n")
if to_do == "1":    
    x = 1
    while x < len(stock_lines):
        if stock_lines[x] < stock_lines[x+1]:        
            print(stock_lines[x-1], "needs restocking (" + stock_lines[x] +  " stock, restock level is", stock_lines[x+1] +")")
        x+=4 #increases x to check the next item

我的问题是,当运行时,它的意思是打印出什么东西需要补充库存(哪些库存水平低于补充库存水平)。这是我使用的股票档案:

^{pr2}$

第一行是项目名称,然后是库存水平,然后是再库存水平,然后是目标库存水平(重新进货时该项目的库存量)。在

当我运行这个:

1. Find items that need to be restocked
1
Egg needs restocking (100 stock, restock level is 50)
Chocolate needs restocking (206 stock, restock level is 300)

如你所见,它告诉我100小于50。任何帮助都会很好。在

我已经试过把100改成101,看看是否是双零影响了它。在


Tags: tolenisstock库存水平itemsopen