试图找出为什么我的程序只允许我输入一个项目,当我尝试输入三个项目时

时间:2017-04-25 02:08:40

标签: python

当我运行我的程序retail_item_list.py时,它会要求我输入第一项,但是,当我完成输入数据后,它只允许我输入一个项目。如果有人知道为什么这样做我会很感激帮助。

这是我用来帮助与主程序交互的Retail类。

class RetailItem:

    def __init__(self, item_description, units_in_inventory, price):

        self.__item_description = item_description
        self.__units_in_inventory = units_in_inventory
        self.__price = price

    def set_item_description(self, item_description):
        self.__item_description = item_description

    def set_units_in_inventory(self, units_in_inventory):
        self.__units_in_inventory = units_in_inventory

    def set_price(self, price):
        self.__price = price

    def get_item_description(self):
        return self.__item_description

    def get_units_in_inventory(self):
        return self.__units_in_inventory

    def get_price(self):
        return self.__price

这是我用来帮助我输入数据的主程序。

import retailitem

def main():

    inventory = make_list()

    print('Here is the data you entered:')
    display_list(inventory)

def make_list():

    item_list = []

    print('Enter data for three items.')
    for count in range(1, 4):
        print('Item Number ' + str(count) + ':')
        item = input('Enter the description of item: ')
        units = float(input('Enter the number of units in inventory: '))
        price = float(input('Enter the price per item: '))
        print()

        items = retailitem.RetailItem(item, units, price)

        item_list.append(items)

        return item_list

def display_list(item_list):
    for item in item_list:
        print(item.get_item_description())
        print(item.get_units_in_inventory())
        print(item.get_price())
        print()

main()

然而,这是我得到的结果。

Enter data for three items.
Item Number 1:
Enter the description of item: 
Jacket
Enter the number of units in inventory: 
12.0
Enter the price per item: 
59.95

Here is the data you entered:
Jacket
12.0
59.95

但我希望它输入三个项目而不仅仅是一个。我想输入的数据是

第1项

描述:夹克

库存中的单位:12

价格:59.95

第2项

描述:Designer Jacket

库存单位:40

价格:34.95

第3项

描述:简短

库存单位:20

价格:24.95

1 个答案:

答案 0 :(得分:2)

$(document).ready( function () {
    var table = $('#example').DataTable({paging:true});
    setInterval(function(){browse(table);} , 5000);
 });

function browse(table){

    if(table.page() >= table.page.info().pages - 1){

        table.page('first').draw('page');

    }
    else {
        table.page("next").draw('page');
    }
 }

问题是return语句的缩进。您的程序在完成循环之前返回列表