There is 5 fundraising projects, and the purpose of this program is to substract the amount of money that each of n donators will donate from the desired sum of each project
The program partially work, but sometimes python typing “TypeError: ‘NoneType’ object is not subscriptable” and the programm fall
What can cause this crash?
Thank you for your help!
JavaScript
x
28
28
1
2
3
n_month = 5
4
nl = [[], [],[], [], []]
5
6
place = 1
7
var = 1
8
9
#creating list of lists of the format [sum, number of project].
10
# for example this one: [[53, 1], [78, 2], [152, 3], [51, 4], [39, 5]]
11
12
for lst in nl:
13
summ = int(input("Please input miminum budget for next project:"))
14
lst.append(summ)
15
lst.insert(place, var)
16
place +=2
17
var+=1
18
19
n = int(input("Please enter number of donors: "))
20
21
for i in range(n):
22
23
project_n = int(input("Please enter project number (1-5): "))
24
donation = int(input("Please enter donation: "))
25
nl[project_n-1][0] -= donation
26
print(nl)
27
28
Advertisement
Answer
You need to reassign the value which you can do with the -=
notation:
JavaScript
1
8
1
nl = [[800, 1], [400, 2]] # each inner list is a fundraising project. the first number in each inner loop refer to the desired amount of money, and the second number is the number of the project
2
3
for i in range(3): # there will be 3 donations, the donator will specify to which project and how much money he want to donate
4
5
project_n = int(input("Please enter project number (1-5): "))
6
donation = int(input("Please enter donation: "))
7
nl[project_n][0] -= donation # here
8