Exemplo n.º 1
0
def display_catalog():
    num_items = len(catalog)  # <- get the length of array or string
    print_header(' Catalog ' + str(num_items) + ' Items')
    print('ID    |  Title              | Category        |     Price | Stock ')
    print('-' * 80)

    for item in catalog:
        print(
            str(item.id).ljust(3) + " | " + item.title.ljust(20) + " | " +
            item.category.ljust(15) + " | " + str(item.price).rjust(9) +
            " | " + str(item.stock).rjust(5))
Exemplo n.º 2
0
def display_categories():
    clear()
    print_header("  Categories  ")
    categories = []
    for item in catalog:
        if( item.category.lower() not in (category.lower() for category in categories) ):
            categories.append(item.category)
            print(item.category)

    if(len(categories) == 0):
        print("*** No categories to display ***")
Exemplo n.º 3
0
def display_no_stock():
    print_header(' Catalog ')
    print('ID    |  Title              | Category        |     Price | Stock ')
    print('-' * 80)

    for item in catalog:
        if (item.stock == 0):
            print(
                str(item.id).ljust(3) + " | " + item.title.ljust(20) + " | " +
                item.category.ljust(15) + " | " + str(item.price).rjust(9) +
                " | " + str(item.stock).rjust(5))
Exemplo n.º 4
0
def cheapest_product():
    clear()
    print_header("  Cheapest Product  ")
    if(len(catalog) == 0):
        print("*** No products in the catalog ***")
    else:
        cheapest_item = catalog[0]
        for item in catalog:
            if(item.price < cheapest_item.price ):
                cheapest_item = item
        print("The Cheapest product it is:")
        print_item(cheapest_item)
Exemplo n.º 5
0
def delete_product():
    print_header("Deleted product")
    display_catalog()
    id = int(input("ID of item to delete: "))
    found = False
    for prod in catalog:
        if(prod.id == id):
            found = True
            catalog.remove(prod)
            print("** Item removed!")
    if(not found):
        print("** Incorrect ID, try again")
Exemplo n.º 6
0
def display_catalog():
    print_header("Items in your catalog")
    print('Id'.rjust(2) + '   ' + 'Title'.ljust(25) + '   ' +
          'Category'.ljust(15) + '   ' + 'Price'.rjust(15) + '   ' +
          'Stock'.rjust(5))

    for item in catalog:
        print(
            str(item.id).rjust(2) + " | " + item.title.ljust(25) + " | " +
            item.category.ljust(10) + " | " + str(item.price).rjust(15) +
            " | " + str(item.stock).rjust(5))
        print('-' * 75)
Exemplo n.º 7
0
def display_no_stock():
    print_header(' Item out of stock')
    print('|ID  | Title               | Category        |     Price | Stock |')
    print('-' * 60)

    for item in catalog:
        if (item.stock == 0):
            print("|" + str(item.id).ljust(3) + item.title.ljust(19) + " | " +
                  item.category.ljust(15) + " | " + str(item.price).rjust(9) +
                  " | " + str(item.stock).rjust(5))

    print('-' * 60)
Exemplo n.º 8
0
def update_product_stock():
    print_header("Update Stock")
    display_catalog()
    id = int(input("Enter ID of item to update: "))
    found = False
    for prod in catalog:
        if(prod.id == id):
            prod.stock = int(input("Enter new stock: "))
            found = True
            print("** Stock updated!")
    if(not found):
        print("** Incorrect ID, try again")
    return found
def most_expensive():
    print_header("3 Most Expensive Products")
    for item in catalog:
        if (item.price == temp_prices[0]):
            print_item(item)

    for item in catalog:
        if (item.price == temp_prices[1]):
            print_item(item)

    for item in catalog:
        if (item.price == temp_prices[2]):
            print_item(item)
Exemplo n.º 10
0
def update_product_price():
    print_header("Update Price")
    display_catalog()
    id = int(input("Enter ID of item to update: "))
    found = False
    for prod in catalog:
        if(prod.id == id):
            prod.price = float(input("Enter new price: "))
            found = True
            print("** Price updated!")
    if(not found):
        print("** Incorrect ID, try again")
    return found
Exemplo n.º 11
0
def most_expensive_items():
    print_header("3 most expensive products prices")
    prices = []
    for prod in catalog:
        prices.append(prod.price)

    # sort the array
    prices.sort(reverse=True)

    # print
    print(prices[0])
    print(prices[1])
    print(prices[2])
Exemplo n.º 12
0
def update_price():
    print_header("update price")
    id = input("choose an id")
    found = False
    for item in catalog:
        if (str(item.id) == id):
            found = True
            print('found it, its:' + item.title)
            price = float(input('Provide new Price$'))
            item.price = price

    if(not found):
         print("error, invalid ID.try again!")
Exemplo n.º 13
0
def most_expensive_items():
    print_header(" 3 most expensive products prices")
    # Create an array of prices (numbers only)
    prices = []
    for prod in catalog:
        prices.append(prod.price)

    # Sort the array 
    prices.sort(reverse=True)

    #print
    print(prices[0]) #find a product
    print(prices[1])
    print(prices[2])
Exemplo n.º 14
0
def three_expensive_products():
    clear()
    print_header("  3 most expensive products  ")
    temp = []
    if(len(catalog) == 0):
        print("*** No products in the catalog ***")
    else:
        temp  = sorted(catalog, key=lambda x: x.price, reverse=True)
        count = 0
        for item in temp:
            print_item(item)
            count+=1
            if(count == 3):
                break
Exemplo n.º 15
0
def delete_product():
    print_header("Find Product ID:(#) in the list")
    display_catalog()
    selected_item = int(input("Enter ID for product to be deleted: "))

    found = False
    for prod in catalog:
        if (prod.id == selected_item):
            found = True
            catalog.remove(prod)
            print("Item deleted")

    if (not found):
        print("** Incorrect ID selected **")
Exemplo n.º 16
0
def cheapest_product_adv():
    print_header(" Cheapest price advance")

    if (len(catalog) < 1):
        print("** Error, empty catalog. Register prods first.")
        return

    cheapest = catalog[0]
    #check if prod is cheaper than cheapest, if it is, then prod is my new cheapest
    for prod in catalog:
        if (prod.price < cheapest.price):
            cheapest = prod

    print_product(cheapest)
    """
Exemplo n.º 17
0
def most_expensive_items():
    print_header(" 3 most expensive product prices")
    # creat an array of prices (numbers only)
    prices = []
    for prod in catalog:
        prices.append(prod.price)

    # sort the array
    prices.sort(reverse=True)

    # print
    print(
        prices[0]
    )  # find  a product with the same price, and print_item (that product)
    print(prices[1])
    print(prices[2])
def register_item():
    try:
        print_header("Register New Item")
        title = input("Please provide Title: ")
        cat = input("Please provide Category: ")
        price = float(input("Please provide Price: "))
        stock = int(input("Please provide Stock: "))

        id = 1
        item = Item(id, title,  cat, price, stock)
        catalog.append(item)

        how_many = len(catalog)
        print("You now have : " + str(how_many) + "item(s) in the catalog ")

    except ValueError:
        print("Error, Please verify data input!")
Exemplo n.º 19
0
def register_product():
    try:
        global next_id
        print_header("Register new Product")
        title = input('Please provide the title: ')
        category = input('Please provide the Category: ')
        stock = int(input('Please provide the initial stock: '))
        price = float(input('Please provide the price: '))

        if(len(title) < 1):
            print("Error: title should not be empty")

        product = Product(next_id, title, category, stock, price)
        next_id += 1
        catalog.append(product)

    except:
        print("** Error, review registration of product")
Exemplo n.º 20
0
def update_stock():
    print_header("Update product stock")

    print_catalog()

    id = input("Choose and id to update: ")
    found = False
    for prod in catalog:
        if (str(prod.id) == id):
            found = True

            newStock = int(input("What is the new stock? "))
            prod.stock = newStock

    if (found):
        print("** Product stock updated!")
    else:
        print("** Error: Invalid ID")
Exemplo n.º 21
0
def delete_product():
    print_header(" Delete a product")

    print_catalog()

    id = input("Choose an id:")

    found = False

    for prod in catalog:
        if (str(prod.id) == id):
            found = True
            catalog.remove(prod)

    if (found):
        print("** Product removed!")
    else:
        print(" ** Error: Invalid ID")
Exemplo n.º 22
0
def register_item():
    try:
        print_header("Register New Item")
        title = input("Please provide the Title: ")
        cat = input("Please provide the Category: ")
        price = float(input("Please provide the Price: "))
        stock = int(input("Please provide the Stock: "))

        id = 1
        item = Item(id, title, cat, price, stock)
        catalog.append(item)

        how_many = len(catalog)
        print("You now have " + str(how_many) + " item(s) on the catalog")
    except ValueError:
        print('Error, incorrect value. Try again.')
    except:
        print("Error, could not load data.")
Exemplo n.º 23
0
def delete_product():
    print_header("Delete produc")

    display_products()

    print("***********************")
    idDeleted = int(input("Give me the ID to deleted:"))
    print("***********************")

    found = False
    for prod in catalog:
        if (prod.id == idDeleted):
            found = True
            catalog.remove(prod)
            print("Product [" + str(idDeleted) + "] as been removed!!!!..")

    if (not found):
        print("ID not founded!!!... try again")
Exemplo n.º 24
0
def register_product():
    try:
        global next_id
        print_header("Register new Product")
        title = input('Please provide te Title: ')
        cat = input('Please provide the Category: ')
        stock = int(input("Please provide initial Stock: "))
        price = float(input("Please provide the Price: "))

        # validations
        if (len(title) < 1):
            print("Error: Title should not be empty")

        product = Product(next_id, title, cat, stock, price)
        next_id += 1
        catalog.append(product)
    except:
        print("** Error, try again")
Exemplo n.º 25
0
def register_item():
    try:
        print_header("Register Item")
        title = input('Please provide the Title: ')
        cat = input("Please provide the category: ")
        stock = int(input("Please provide initial stock: "))
        price = float(input("Please provide the price: "))

        item = Item(0, title, cat, stock, price)
        # add item to the catalog list
        catalog.append(item)

        print("** Item Saved! **")

    except ValueError:
        print("** Error, incorrect input, fix and try again")
    except:
        print('** Error, something went wrong! **')
Exemplo n.º 26
0
def register_item():
    print_header('Register new Item')

    try:
        title = input("Item Title:  ")
        cat = input("Item Category: ")
        price = float(input("Item Price: "))
        stock = int(input("Items in Stock: "))

        # create an instance of Item (an object)
        new_item = Item(1, title, cat, price, stock)
        catalog.append(new_item)

        print("Item created ")

    except ValueError:
        print("** Error: incorrect value, try again")
    except:
        print("** Error, try again")
def expensive_products():
    print_header("The 3 most expensive products")
    prices = []
    for item in catalog:
        prices.append(item.price)

    prices.sort(reverse=True)

    for item in catalog:
        if (item.price == prices[0]):
            print_item(item)

    for item in catalog:
        if (item.price == prices[1]):
            print_item(item)

    for item in catalog:
        if (item.price == prices[2]):
            print_item(item)
Exemplo n.º 28
0
def register_item():
    try:
        print_header("Register New Item")
        title = input('Please provide the Title: ')
        cat = input('Please provide the Category: ')
        price = float(input('Please provide the Price: '))
        stock = int(input('Please provide the Stock: '))

        id = 1
        item = Item(id, title, cat, price, stock)
        catalog.append(item)

        how_many = len(catalog)
        print("You now have: " + str(how_many) + " items on the catalog")

    except ValueError:
        print("Error: Incorrect value, try again")
    except: 
        print("Error, Somthing went wrong")
Exemplo n.º 29
0
def register_item():
    global last_id
    try:
        print_header("Register a new Item")
        title = input('please provide the Title: ')
        cat = input('please provide the Category: ')
        stock = int(input('please provide initial Stock: '))
        price = float(input('please provide the Price: '))

        item = Item(last_id, title, cat, stock, price)
        last_id = last_id + 1
        catalog.append(item)

        print(" ** Item Saved! **")

    except ValueError:
        print('** Error, incorrect input fix and try again **')

    except:
        print('** Error, something went wrong **')
Exemplo n.º 30
0
def register_product():
    global next_id  #have to do this because python is picky with global variables

    try:
        print_header("Register your new product")
        title = input('Please provide the Title: ')
        cat = input('Please provide the Category: ')
        stock = int(input('Please provide initial Stock: '))
        price = float(input('Please provide the Price: '))

        #validations
        if (len(title) < 1):
            print("*Error: Title should not be empty")

        product = Product(next_id, title, cat, stock, price)
        next_id += 1
        catalog.append(product)

    except:
        print("** Error: make sure to enter only integers for stock and price")
Exemplo n.º 31
0
Arquivo: main.py Projeto: adrisons/ATF
from menu import print_header
from menu import sel_code
from menu import csv_to_matrix
from menu import the_end

emisor = 'em_ber.csv'
receptor = 'rec_ber.csv'

print_header()
checker = sel_code()

code_sent = csv_to_matrix(emisor)[1]
code_recv = csv_to_matrix(receptor)[1]

if checker(code_sent,code_recv):
	print ' |        > Correct <' + ' '*15 +'|'
else:
	print ' |        > Incorrect <' + ' '*13 +'|'

the_end()