Nov-27-2018, 08:55 PM
(Nov-27-2018, 07:46 PM)ichabod801 Wrote: Infor bal in accountBalance:
, bal is independent of accoutBalance, so changing bal does not change accountBalance. So at the end, all the values are still 0. I would redo the first loop as:
accountBalance = [] for value in range(5): accountBalance.append(float(input('Enter value: ')))
I realized that the way I wrote it, I created the list and then created a separate loop to total the list. However, since the list was already created in the previous loop, there was nothing to total up. I rewrote it this way before seeing your comment, though yours would obviously work as well, this way worked just fine for the simple tasks I was asking. For more complicated lists and processing I think I should use your method.
#Create List with user input accountBalance = [0] * 5 total = 0 for bal in accountBalance: bal = float(input("Enter")) total += bal #Procces list for total and average average = total / len(accountBalance) print("Total: ", total) print("Average: ", round(average, 2))