2014-02-19 32 views
0

我一直被困在編程練習一段時間。我寫了一個基本程序,練習要求我打印出框架堆棧。我試過的所有方法都沒有打印出我需要的信息。Python混淆 - 打印一個簡潔的框架堆棧

這是我簡單的程序,

#! /usr/bin/python 
import math 

def square(x): # returns the sqare of x 
    return x*x 

def hyp(x, y): # returns the size of vector (x,y) 
    return math.sqrt(square(x) + square(y)) 

def compVectLen(x1,y1, x2,y2): # compares the size of two vectors 
    return hyp(x1,y1) >= hyp(x2,y2) 

print compVectLen(2,2, 7,7) 

,這是鍛鍊是如何要求的堆棧幀顯示,

|---------------compVectLen---------------­­­­­­­­­­­­­| 
| Locals: x1=2,y1=2, x2=7,y2=7   ­| 
| return hyp(x1,y1) >= hyp(x2,y2)   | 
|­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­-----------------------------------------| 
|­­­­­­­­­­­­­­­---------------hyp(x1, y1)---------------­­­­­­­­­­­­| 
| Locals: x=2,y=2      ­ | 
| return math.sqrt(square(x) + square(y)) | 
|-----------------------------------------| 
|­­­­­­­­­­­­­­­----------------square(x)----------------­­­­­­­­­­­­­­| 
| Locals: x=2,       ­ | 
| return 2*2        | 
|­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­-----------------------------------------| 

我試圖給我的結果的所有方法,但沒有儘可能多的信息,也沒有這種風格。

任何幫助,將不勝感激。

+0

您嘗試過哪些方法?練習是否要求您自己編寫堆棧框架的輸出? –

+0

這個練習是措辭; 「修改 幻燈片32中的示例程序」compVectLen「,以使其打印出來,同時 評估,堆棧框」調試「信息 類似於幻燈片34至49中打印的信息。」至於我所嘗試的,我已經使用回溯和檢查,並沒有打印一個調用堆棧,如示例要求... – user3329406

回答

0

def compVectLen(x1,y1, x2,y2): # compares the size of two vectors 
return hyp(x1,y1) >= hyp(x2,y2) 

你不給任何條件。你只需返回hyp(x1,y1) >= hyp(x2,y2),這將始終返回x1,y1值更大。

+0

該腳本只是返回true或false取決於我的「打印compVectLen(2,2, 7,7)「線說。我仍然在進行非常基本的編程練習。 – user3329406