forked from hogwild/Week6_Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxsum_student.py
52 lines (38 loc) · 1.01 KB
/
maxsum_student.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
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 14 14:11:20 2017
@author: Mebius
"""
import random
random.seed(0)
TRI_DEPTH = 5
class Triangle:
def __init__(self, up_t=None):
self.up_t = up_t
self.size = 1 if up_t == None else up_t.get_size() + 1
self.my_row = [random.randint(0, 20) for i in range(self.size)]
self.maxsum = []
def get_size(self):
return self.size
def get_maxsum(self):
#write your code here, and be sure to return what you've done
return
def print_triangles(ts):
for t in ts:
print(t.my_row)
def print_maxsum(ts):
for t in ts:
print(t.maxsum)
def main():
tri = []
for i in range(TRI_DEPTH):
try:
tri.append(Triangle(tri[i-1]))
except:
tri.append(Triangle())
print("triangle -- ")
print_triangles(tri)
tri[TRI_DEPTH - 1].get_maxsum()
print("\nmaximum sum -- ");
print_maxsum(tri)
main()