Friday, February 8, 2019

codingdirectional: Counts the points of our team in the championship

Hello and today we will continue to solve the problem posted on codewars, if you have not yet joined codewars then I really encourage you to do so because this site is a real deal for those of you who want to master the Python programming language. In this latest chapter, we will need to write a function that takes such a list and counts the points of our football team in the championship. Rules for counting points for each match are as follows.

  1. if x>y – 3 points
  2. if x<y – 0 point
  3. if x=y – 1 point

We will first split the items in a list into two parts, then we will compare the first part with the second part and add up the points accordingly.

def points(games):
    
    total = 0
    for points in games:
        c_point = points.split(':')
        if(int(c_point[0]) > int(c_point[1])):
            total += 3
        elif(int(c_point[0]) == int(c_point[1])):
            total += 1

    return total

The solution is short and simple, if you have a better solution then do comment on the below tweet so others can learn from you as well.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...