-1

This program should give me the total amount to be paid taking into account all the products that have been introduced by the user. The problem: When creating the list "Amounts_list" looks like values are not getting added to the list.

products_invoice = []

Totals = []

def interaction():

*#selecting first product/quantity*

code = int(input("add article code: "))

price = {1: 5, 2:10, 3:15, 4:20, 5:25, 6:30, 7:35, 8:40, 9:45, 10:50} 

*#article with code 1 costs 5$*

print(f"The price is: {price[code]} $")

quantity = int(input("add quantity: "))

print(f"The total to be paid is: {((price[code])*quantity)} $")

product = code, price[code]*quantity

global products_invoice

products_invoice.append(product)
print(f"products invoice: {products_invoice}") #to debug
product_to_list = list(product) *#converting to a list to be able to extract product[1]*
Amount = product[1]
print(Amount)

global Totals *#creating a new list to add Amount/product[1] which later on I want to add up*
Amounts_list = Totals.append(Amount) 
print(Amounts_list)  **#I get a None instead of printing the list.**

*#adding up the product[1] amounts/costs of all the introduced articles, to get the grand total.*
Grand_Total = sum(Amounts_list,0)
print(Grand_Total)
Marta
  • 3
  • 2
  • 1
    Does this answer your question? [Why does list.append() return None?](https://stackoverflow.com/questions/20016802/why-does-list-append-return-none) – Corentin Pane Nov 05 '19 at 12:23

1 Answers1

0

Amounts_list = Totals.append(Amount) assigns the result of .append to Amounts_list, and this result is always None.

You might want to write Amounts_list = Totals + [Amount] instead.

Corentin Pane
  • 4,794
  • 1
  • 12
  • 29
  • thanks for your answer. however, i dont understand why i get the None value. plus, when i write Amounts_list = Totals + [Amount] it is not adding up all the values...values are not getting stored within the list Amounts_list... – Marta Nov 05 '19 at 12:35
  • `.append()` doesn't return a new list, it just returns `None`. I suggest reducing your code to the bare minimum needed to understand your issue better. – Corentin Pane Nov 05 '19 at 12:37
  • Many thanks for clarifying and for your comments. I'll do so. – Marta Nov 05 '19 at 13:08