小编use*_*075的帖子

树蟒的深度

我是编程的新手,我正在尝试计算python树的深度.我相信我的错误是因为深度是Node类的一种方法而不是常规函数.我正在努力学习oop并且希望使用一种方法.这可能是一个新的蜜蜂错误...这是我的代码:

class Node:

    def __init__(self, item, left=None, right=None):
        """(Node, object, Node, Node) -> NoneType
        Initialize this node to store item and have children left and right.
        """
        self.item = item
        self.left = left
        self.right = right

    def depth(self):
        if self.left == None and self.right == None:
            return 1

        return max(depth(self.left), depth(self.right)) + 1

i receive this error:

>>>b = Node(100)

>>>b.depth()

1 

>>>a = Node(1, Node(2), Node(3))

>>>a.depth()

Traceback (most recent call last):
  File "C:\Program Files\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line …
Run Code Online (Sandbox Code Playgroud)

python oop methods tree

9
推荐指数
1
解决办法
9922
查看次数

在C中使用scanf进行解析

我是第一次学习C语言.

我有一个指向一个名为goalie_stat的字符串的指针(见下文).我如何使用scanf来解析保存百分比,即933,然后将933分配给变量然后最终打印出来?

char *goalie_stat = "PatRoy 2.28  933  35  12  165 199  4   5500"

char save_p = scanf("%[13-15]", goalie_stat);
printf("%s", save_p);
Run Code Online (Sandbox Code Playgroud)

'933'是字符串的第13,14和15个字符,但我知道这是不正确的

c parsing pointers input scanf

2
推荐指数
1
解决办法
517
查看次数

标签 统计

c ×1

input ×1

methods ×1

oop ×1

parsing ×1

pointers ×1

python ×1

scanf ×1

tree ×1