Skip to content Skip to sidebar Skip to footer

Project 2 Human Pyramid Calculations

For simplicity we will assume that everyone in the pyramid weighs exactly 200 pounds. Person A at the top of the pyramid has no weight on her back. People B and C are each carrying

Solution 1:

Using global variables suggests that you haven't considered this recursively.

Each person shoulders half the weight of the persons on each shoulder. The effective weight of each person is what they shoulder, plus 200 pounds. If a person is on the edge, then the "person" on the other shoulder has 0 weight.

So ...

def weight(r,c):# Code base casesif r <0:# Past the pyramid top; no such personreturn0ifc<0 or c> r:# Off the edge; no such personreturn0return200+(weight(r -1,c-1)+ weight(r -1,c))/2

Then weightOn is simply the above routine without the 200 +.

That's your outline; can you take it from there?

Solution 2:

defweight_on (r,c):
    
    second_person = 200#finds out if there is a second person on top or notif c - 1 < 0or c > r - 1 :
        second_person = 0if c < 0or c > r:
        return0elif r <= 0:
        return0else:
        return (second_person + 200 + weight_on (r - 1,c - 1) + weight_on (r - 1,c))/2

Post a Comment for "Project 2 Human Pyramid Calculations"