小编Mat*_*ard的帖子

无法理解递归

我正在这里进行第一次递归练习:http : //cscircles.cemc.uwaterloo.ca/16-recursion/

我遵循了明显的提示并做了以下操作:

def countup(n):
  if n == 0:
    print('Blastoff!')
  else:
    countup(n - 1)
    print(n)
Run Code Online (Sandbox Code Playgroud)

因此,代码基本上从0(blastoff)递增到n。我只是不明白它是如何工作的-我在可视化仪中查看,它经过countup(n)到countup(0),这时它打印的是“ Blastoff”,都很好。之后,它...停留在else循环中,并开始打印出先前的n个值..为什么这样做呢?它是否出于某种原因存储了n个值,即使该代码机制如何工作也确实如此?任何帮助将不胜感激。非常感谢。

python recursion python-3.x

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

Python While循环语法

class Solution: 
    def display(self,head):
        current = head
        while current:
            print(current.data,end=' ')
            current = current.next
Run Code Online (Sandbox Code Playgroud)

你好,我在理解上面的循环时有些困难,AFAIK你需要有一个while循环的条件,所以:

while (stuff) == True:
Run Code Online (Sandbox Code Playgroud)

但上面的代码有:

while current:
Run Code Online (Sandbox Code Playgroud)

这是一样的:

while current == head:
Run Code Online (Sandbox Code Playgroud)

谢谢

python loops while-loop

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

R中的条件公式

如果我有条件公式,那么:

时间<theta:y = x ^ 2

time => theta:y = x

我如何使用R中的as.formula函数来构建类似的东西?(我也需要在它上面使用nls函数).

我试过了:

Data2 <-as.formula(y ~ (x<=theta)*x^2 + (x>theta)*x)
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

math r

-3
推荐指数
1
解决办法
406
查看次数

标签 统计

python ×2

loops ×1

math ×1

python-3.x ×1

r ×1

recursion ×1

while-loop ×1