1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Recursive solution?

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    QUESTION: we've got 3 kind of coins($1,$2,$5) and we are going to have a mixture of these coins in order to make $1000 ; we want the number of all possible ways of creating $1000 using these coins and also we need to print each possible way

    I've just write the below code for the question of coins in a non-recursive style and it is working properly. now I need to wite a recursive function that do the same thing but I just can't figure out the base case of my recursive function.any ideas for writing a recursive function?

    i=0
    for x in range(1001):
    for y in range(501):
    for z in range(201):
    if x + 2*y + 5*z == 1000:
    print(" {} coin $1 , {} coin $2 , {} coin $5".format(x,y,z))
    i+=1
    print("number of possibilities",i)

    Continue reading...

Compartilhe esta Página