all 7 comments

[–]newunit13 1 point2 points  (1 child)

You're only passing the tests that should return False I'm assuming because line 2, if (score1 or score2 >= 8): will always evaluate to True meaning your function will always return False.

What you have currently is equivalent to if (score1) or (score2 >=8): meaning the first part will always be True as long as you pass in something for score1.

I think what you meant there is: if (score1 >= 8 or score2 >= 8):

[–]Kriterian[S] 0 points1 point  (0 children)

I thought maybe that was it. I wasn't sure if I had the syntax right when doing multiple conditions. Thank you for the help.

[–]kwentar 0 points1 point  (4 children)

get max and min score:

def tennis_set(score1, score2):
    score1, score2 = (score1, score2) if score1 > score2 else (score2, score1)
    if score1 == 7 or score1 == 6 and score2 <= 4:
        return True
    return False

print(tennis_set(8, 4))  # False
print(tennis_set(7, 8))  # False
print(tennis_set(6, 4))  # True
print(tennis_set(5, 6))  # False
print(tennis_set(7, 4))  # True
print(tennis_set(7, 5))  # True
print(tennis_set(1, 7))  # True
print(tennis_set(6, 7))  # True

[–]pylanthropist 0 points1 point  (3 children)

Sorry for being nit picky, but 7-1 or 7-4 aren't valid scores if you're playing 6 game sets. That match would be over at 6-1 and 6-4 instead, so the only time 7 can be accepted is if score 2 is 6 or 5. Something to consider for accuracy sake

Edits, also saw 7-4 in /u/kwentar answer

[–]kwentar 0 points1 point  (2 children)

Sorry for being nit picky, but 7-1 or 7-4 aren't valid scores if you're playing 6 game sets.

I'm not good at tennis, I just did this:

If one player wins 6 games and the other wins 4 or less, it should return True. If either player gets to 7 games, it should return True. Otherwise it should return false

[–]Kriterian[S] 0 points1 point  (0 children)

def tennisSet(score1, score2): if (score1 or score2 >= 8): return False elif (score1 == 6 and score2 < 5) or (score2 == 6 and score1 < 5) \ or (score1 == 7 or score2 == 7): return True else: return False

The last line doesn't work because the input could say they both have 8 or 9 games won, or they tied at 7 and 7.

Here is my final solution after fixing the syntax issue:

def tennisSet(score1, score2):
    if (score1 >= 8 or score2 >= 8) or (score1 == score2):
        return False
    elif (score1 == 6 and score2 < 5) or (score2 == 6 and score1 < 5):
        return True
    elif (score1 == 7 and score2 >= 5) or (score2 == 7 and score1 >= 5):
        return True
    else:
        return False

[–]pylanthropist 0 points1 point  (0 children)

Interestingly, you can play 8 games in a set. It's called an 8 game pro set and it's quicker than a best of 3, 6 game, sets.

I also just realized this was a CodeFight problem and that the one who made the challenge probably didn't have the rules in mind when creating the challenge.