-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssignment- 206009L.py
45 lines (31 loc) · 945 Bytes
/
Assignment- 206009L.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
# Chirasthi Amarasingha - 206009L
# This algorithm takes a list of donations and ensures that the non-neighbour donations are maximized
donation = []
total_odd = 0
total_even = 0
has_donated_odd = []
has_donated_even = []
not_done = True
while not_done == True:
prompt = input("Continue? (y/n): ")
if prompt == "y":
x = input("Enter donation: ")
donation.append(int(x))
else:
not_done = False
for i, v in enumerate(donation):
if (i==0) or (i%2 == 0):
total_even = total_even + v
has_donated_even.append(v)
else:
total_odd = total_odd + v
has_donated_odd.append(v)
if total_even > total_odd:
print(has_donated_even, "donations provide the maximum of %d." %total_even)
else:
print(has_donated_odd, "donations provide the maximum of %d." %total_odd)
for x in range(0,20):
print(x)