How to create a single file that stores the details of the generated information (order)?

Asked

Viewed 41 times

0

    have_discount = []

    no_discount = []

    for each_price in purchases_prices:
        b = bool_gen(p)
        if b:
            have_discount.append(apply_discount(each_price,b))
            have_discount = [round(each_price, 2) for each_price in have_discount]
        else:    
            no_discount.append(apply_discount(each_price,b))        

    #games_tags
    games_tags = []
    for code_game, game_name in stock.items():
        if code_game in codes_being_purchased:
            games_tags.append(game_name)

    #cost of all itens
    total_cost = round(sum(have_discount) + sum(no_discount),2)

    #total discount 
    total_discount = round(sum(purchases_prices) - total_cost,2)

    print('Dear customer', customer_id,',' , 'your order_id is',order_id,'and it contains',len(games_tags),'itens, which makes a total cost of', round(total_cost,2), 'and a discount was applied to', len(have_discount),'itens.') 
    print('Thanks for choosing us!')
 O que retorna da função é:
 Dear customer 8890 , your order_id is 26287 and it contains 6 itens, which makes a total cost of 256.2 and a discount was applied to 4 itens
 Dear customer 8655 , your order_id is 5259 and it contains 6 itens, which makes a total cost of 247.77 and a discount was applied to 7 itens.

 Dear customer 8400 , your order_id is 48297 and it contains 3 itens, which makes a total cost of 72.47 and a discount was applied to 1 itens.

I would like to store all the information of each order as follows(and based on the example):

tuple = (8890,26287,6,256.2,4),(8655,529,6,247.77,7),...)

Update:

    list_discount = []
    list_customer_id = []
    list_order_id = []
    list_games_tags = []
    list_total_cost = []
    for info in range(customers):
        list_customer_id.append(customer_id)
        list_order_id.append(order_id)
        list_games_tags.append(len(games_tags))
        list_total_cost.append(total_cost)
        list_discount.append(len(have_discount))
    order_tuple =(list_customer_id,list_order_id,list_games_tags,list_total_cost,list_discount)
        return order_tuple

customerSim(10)

Output of append:

([429, 429, 429, 429, 429, 429, 429, 429, 429, 429],
 [25835, 25835, 25835, 25835, 25835, 25835, 25835, 25835, 25835, 25835],
 [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
 [280.42,
 280.42,
 280.42,
 280.42,
 280.42,
 280.42,
 280.42,
 280.42,
 280.42,
 280.42],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
  • I wanted to create a Tuple that would store all the order details... as described in the figure above...I created a function that randomly generates orders! and wanted to store in a single store the generated info of each

  • Apparently you’ve done everything.. Wouldn’t it just be creating the tuples with the value you want? Like (customer_id, order_id, len(game_tags), round(total_cost, 2), len(have_discount))??

  • yes but I am not able to iterate each value of each client...

  • just create an empty list and give a append after each of the values has been calculated. If you search here on the site you should find many examples to study...

  • I’ve done it but I couldn’t...!

  • only stores the info of the last client... and I wanted from all(from first to last)

  • Your weird code ta, only ta being kept a value in every array because you are using the same variable always. You have the info generated from a range, but in no time do you use it. No list_customer_id you giving append in the same variable customer_id without updating her.

  • I imagine in the case of the first line it should be something like: for info in range(len(customers)): list_customer_id.append(customers[info][customer_id])

  • Not that that’s it, but I think you can get an idea.

  • I confess that I did not understand the problem. So I return with a question: are you sure you want to use tuple as a data structure? I believe a list of objects, or a list of namedtuples (from collections import namedtuple), or a list of dictionaries would be much more appropriate

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.