簡體   English   中英

Python困惑-打印簡潔的框架堆棧

[英]Python confusion - Printing a concise frame stack

我被卡在編程練習上一段時間了。 我編寫了一個基本程序,練習要求我將其打印出框架堆棧。 我嘗試過的所有方法都沒有打印出我需要的信息。

這是我的簡單程序,

#! /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                              |
 |­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­-----------------------------------------|

我嘗試過的所有方法都給了我結果,但是信息不多,也不是這種風格。

任何幫助,將不勝感激。

在你的

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更大的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM