Relative Content

Tag Archive for pythonrecursion

Python Function Losing List Element After Recursion?

I’ve just started learning Python and I’m getting a weird error in an exercise program I have just written. The program takes in a list of tuples (freq_i, value_i) representing a histogram of distinct value_is, and is supposed to output a list of list of first permutations which I could then permute in turn to get all possible unique combinations of k chosen elements from the original list from which the input histogram was generated. Sorry, if that’s not a clear explanation. My test case is as follows. Hopefully this will help clarify what it is supposed to do.

Why is this recursive algorithm in python working?

def Summ(x): while x<100: x=x+1 print(x) Summ(x) return What am I missing here? There is no error and no ouput either ! I was expecting to get x as the ouput until it’s values reaches 100 but nothing happened. For eg. if I enter Summ(2), the result should be : 3 4 5 6 . […]

How to match video duration with music’s duration?

I have a video file and music files, I want to match the video duration with multiple musics in min diff = ideo duration, sum of musics duraion. I use code as below, but it looks like not all answers, what can I get all combination? do I have to use recursion?

How to write a function that converts a number into a different base

def Conversion(num,base): if num == 0: return “” else: remainder = (num % base) remainder = str(remainder) remainder = remainder + str(Conversion((num – int(remainder)) // base, base)) return remainder print(Conversion(153,4)) My code outputs 1212 instead of 2121 I tried to concatenate the remainder string with a recursively called version of the same code but 1 […]