Codewars Failing Tests help

Hey there, I am having the issue on Codewars where I pass all the basic tests but somehow I am failing the random tests. Here our two separate problems where I feel like I’ve written good working code but its not letting my attempt pass.

Problem 1:

Thinkful - Dictionary drills: Order filler

You’re running an online business and a big part of your day is fulfilling orders. As your volume picks up that’s been taking more of your time, and unfortunately lately you’ve been running into situations where you take an order but can’t fulfill it.

You’ve decided to write a function fillable() that takes three arguments: a dictionary stock representing all the merchandise you have in stock, a string merch representing the thing your customer wants to buy, and an integer n representing the number of units of merch they would like to buy. Your function should return True if you have the merchandise in stock to complete the sale, otherwise it should return False .

Valid data will always be passed in and n will always be >= 1.

MY CODE:

def fillable(stock, merch, n):
    if merch in stock:
        quantity = stock[merch]
        if n > quantity:
            return False
        elif n < quantity:
            return True
    else:
        return False

Problem 2:

Return the first M multiples of N

Implement a function, multiples(m, n) , which returns an array of the first m multiples of the real number n . Assume that m is a positive integer.

Ex.

multiples(3, 5.0)

should return

[5.0, 10.0, 15.0]

MY CODE:

def multiples(m, n):
    list = []
    num = 0
    n = int(n)
    for i in range(m):
        num = n * (i+1)
        num = float(num)
        list.append(num)
    return list

Error message for problem 1 is "none should equal True"
Error message for problem 2 is " [3.0] should equal [3.14]"

Any help figuring this out is greatly appreciated.

Thanks

you have not given the links so I can just imagine

what about if both conditions are false? there is a case in which that is a possible

can you explain why this line?

1 Like
  • BOTH PROBLEMS SOLVED *

I wasn’t sure if I was allowed to link to other coding sites on here.

Here is the link for both problems.

problem 1 -

problem 2 - https://www.codewars.com/kata/593c9175933500f33400003e/train/python

And for the first code snippet you posted. I just figured it out.

n is equal to the amount the customer wanted
quantity was equal to the quantity we had in stock
with my old line of code

elif n < quantity:
            return True

I was saying we would return True and fulfill the order if the customer wanted less than the amount of quantity we had in stock.

I needed to change

elif n <= quantity:
            return True

Because in fact we could still fulfill the order if the amount they wanted was equal to our quantity, not just less than.

So now I’m only stuck on problem 2.

Thanks for that code snippet you posted. That line is actually useless. For some reason I thought it was giving me an error trying to work with the float passed in so I thought I had to convert it out of a float and into an int and then back to a float. I’m seeing now that is not the case and I can use a float the whole way.

So the new code would look something like this.

def multiples(m, n):
    list = []
    num = 0
    for i in range(m):
        num = n * (i+1)
        list.append(num)
    return list
    
    
multiples(3, 5.0)

And now that test is passing as well … /:

You’ve solved both my problems by just assessing the code lol.

Thank you!

  • I’d still be curious why changing it from an float to an int back to an float throws an error I would think it would be the same thing as starting with a float and using it throughout

the test you were failing was calling multiples(3.14, 1), try to see what it returns with both versions of the code