Linked Questions

31 votes
5 answers
74k views

Basics of recursion in Python

"Write a recursive function, "listSum" that takes a list of integers and returns the sum of all integers in the list". Example: >>> listSum([1, 3, 4, 5, 6]) 19 I know ...
Sebastian S's user avatar
-2 votes
2 answers
311 views

Is This An Example Of Recursion (Python) [duplicate]

Hi I am struggling to understand exactly what recursion is, It is a requirement of the program I am writing(a snake game) and I cannot find a clear definition of what is classified as recursion. Could ...
BoJ's user avatar
  • 25
0 votes
0 answers
35 views

Python loop and listing issue [duplicate]

Can anyone help me with my code, I just cant seem to see the problem. I am new yo programming so it probably really easy to see. I am using 4 birthday gifts as an example. x = input("How many ...
2beasty4u's user avatar
8 votes
3 answers
39k views

python - calling a function from within itself

The code I already have is for a bot that receives a mathematical expression and calculates it. Right now I have it doing multiply, divide, subtract and add. The problem though is I want to build ...
Omar Saad's user avatar
  • 243
9 votes
5 answers
36k views

How to get leaf nodes of a tree using Python?

Hi there I am new to OOP so have this in mind while you are reading this. I have a simple Python tree implementation(see below code). class TreeNode(object): def __init__(self, data): ...
limitcracker's user avatar
  • 2,248
9 votes
7 answers
958 views

How can I apply a function to itself?

Suppose I have function, f, which takes in some variable and returns a variable of the same type. For simplicity, let's say def f(x): return x/2+1 I'm interested in applying f to itself over ...
Demetri Pananos's user avatar
2 votes
3 answers
8k views

maximum recursion depth exceeded while calling a python object

My aim is to instantiate a class called arrow, so I can have more arrows then just 1. I wanted to start with the coordinates 200, 200 and want to increase x by 15 per every 100 milliseconds. But when ...
BoJack Horseman's user avatar
0 votes
4 answers
2k views

Python: How to write a function which loops over itself with a number of its arguments? [closed]

This simple loop works just fine: >>> def loop (i): i+=i if 0<i<20: print i loop(i) >>> loop (1) 2 4 8 16 But this one doesn't work ...
Dusk's user avatar
  • 1,769
2 votes
1 answer
4k views

How to get all comments of a facebook post using facebook SDK in Python?

I want to get all comments of a facebook post. We can extract comments by passing the limit() in Api call But how we know the limit? I need all comments. https://graph.facebook.com/...
Amar's user avatar
  • 885
-4 votes
3 answers
4k views

How to multiply without the * sign using recursion?

so as homework for a programming class on python we're supposed to multiply to integers (n,m) with each other WITHOUT using the * sign (or another multiplication form). We're supposed to use recursion ...
Domi's user avatar
  • 11
1 vote
2 answers
149 views

What is the type of parameter, and what does this function do?

I am having trouble with the code below: def myprogram(x): if x == []: return x else: return myprogram(x[1:]) + [ x[0] ] What is the parameter type (x)? What does this ...
Jack's user avatar
  • 17
-1 votes
1 answer
623 views

Boolean interpretation and recursion function

1.) I want to confirm that I indeed need four boolean variables to answer the question below e.g. p,q,x,y 2.) I need to write a recursive function to parse and interpret this. Boolean statement: ...
whalekayo's user avatar
0 votes
1 answer
755 views

Recurive game in pygame, using recursive rectangles.(pygame)

Ive been trying to make a recursive rectangles and I wanted to make the rectangles move in the forward direction like each time it recursed, so that it gives a motion as one is going into an endless ...
Anim3boy's user avatar
-1 votes
2 answers
144 views

Coding summation formula and recursive function [closed]

Python beginner, running 2.7 I would like to define a function in Python, say N(d), recursively; with the following property: It sums the products a*b*N(a)N(b), for a and b integers greater than or ...
Jr.'s user avatar
  • 101
0 votes
3 answers
235 views

arbitrary operation on list

["add",["subtract",["multiply",2,["add",1,3]], 4 ] , 5 ] how can I do these operation when prog see "add" it adds 1 and 3 and return 4 new list became ["add",["subtract",["multiply",2, 4 ], 4 ] ,...
user avatar

15 30 50 per page