0

I am having an equality issue. The following code compares the nested lists to the list dice.

def largeStraight(dice):
    straightValues = [{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}]
    return any(value.issubset(dice) for value in straightValues)

def smallStraight(dice):
    straightValues = [{1, 2, 3, 4}, {2, 3, 4, 5} , {3 ,4, 5, 6}]
    return any(value.issubset(dice) for value in straightValues)

def giveResult(dice):
    score = 0
    if(largeStraight):
        score = 40
    elif(smallStraight):
        score = 30
    else:
        score = 0
    return score

dice = [1,2,3,4,1]
print(giveResult(dice))

This should return a value of 30 from giveResult, however I am getting a score of 40.

1
  • First thing you need to do is largeStraight(dice) and smallStraight(dice). You aren't passing dice, but instead are evaluating truthiness of a function, which is True. Commented Nov 22, 2013 at 15:59

2 Answers 2

3

You need to call your functions:

def giveResult(dice):
    score = 0
    if largeStraight(dice):
        score = 40
    elif smallStraight(dice):
        score = 30
    else:
        score = 0
    return score

Just referring to a function object means your first if will match, as most Python objects are considered true in a boolean context.

You can return early, simplifying your function a little:

def giveResult(dice):
    if largeStraight(dice):
        return 40
    if smallStraight(dice):
        return 30
    return 0
Sign up to request clarification or add additional context in comments.

Comments

0

You're not passing anything into your methods:

def giveResult(dice):
    score = 0
    if(largeStraight(dice)):
        score = 40
    elif(smallStraight(dice)):
        score = 30
    else:
        score = 0
    return score

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.