0

I am trying to write a program that will receive inputs, run some calculations and store them in a list before adding the elements of the list. but I keep getting the error: wh_list = wh_list.append(wh) AttributeError: 'NoneType' object has no attribute 'append'

code:

wh_list = []
u = len(wh_list)
if u <= 1:
    while True:
        inp = input("Y or N:")
        B = int(input("B value:"))
        C = int(input("C value:"))
        D = int(input("D value:"))
        wh = B * C * D
        wh = int(wh)
        wh_list = wh_list.append(wh)
        if inp == "Y":
            break
else:
    Ewh = sum(wh_list)
    print(Ewh)
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

1 Answers1

0

append changes the list and returns None. Thus,

wh_list = wh_list.append(wh)

will

  • append wh to wh_list
  • assign None to wh_list

In the next iteration, it will break, as wh_list is a list no more.

Instead, write just

wh_list.append(wh)
Amadan
  • 191,408
  • 23
  • 240
  • 301