Skip to main content
Commonmark migration
Source Link

DRY

#DRY ThisThis repetitive code is an anti-pattern:

blueTotal = 0
greenTotal = 0
redTotal = 0
yellowTotal = 0

Please define

houses = 'blue green red yellow'.split()

and then you can use array access to perform "the same action" across all houses:

for house in houses:
    total[house] = 0

One could also assign total = collections.defaultdict(int), but that would be a horse of a different color. (https://docs.python.org/3/library/collections.html#collections.defaultdict)

global

#global TheThe global keyword is usually not your friend, it leads to unfortunate coupling. Here, it is offering you a hint that you want to define a class, set totals to zero in the __init__() constructor, and then have places() access self.total[].

arg passing

#arg passing ThisThis is a bit crazy:

    for competitors in competitorDetails:
        points()

Yes, you can treat competitors as an implicit argument by making it global, but there is absolutely no reason to, and the current code makes it extremely difficult for readers to understand what is going on. Please, please make competitors an explicit argument, passing it in with points(competitors).

formatting

#formatting ClearlyClearly this works:

print("blueTotal " + str(blueTotal))

but the explicit call to str is slightly verbose. Consider re-phrasing such print statements in one of these ways:

print("blueTotal", blueTotal)
print(f'blueTotal {blueTotal}')

#DRY This repetitive code is an anti-pattern:

blueTotal = 0
greenTotal = 0
redTotal = 0
yellowTotal = 0

Please define

houses = 'blue green red yellow'.split()

and then you can use array access to perform "the same action" across all houses:

for house in houses:
    total[house] = 0

One could also assign total = collections.defaultdict(int), but that would be a horse of a different color. (https://docs.python.org/3/library/collections.html#collections.defaultdict)

#global The global keyword is usually not your friend, it leads to unfortunate coupling. Here, it is offering you a hint that you want to define a class, set totals to zero in the __init__() constructor, and then have places() access self.total[].

#arg passing This is a bit crazy:

    for competitors in competitorDetails:
        points()

Yes, you can treat competitors as an implicit argument by making it global, but there is absolutely no reason to, and the current code makes it extremely difficult for readers to understand what is going on. Please, please make competitors an explicit argument, passing it in with points(competitors).

#formatting Clearly this works:

print("blueTotal " + str(blueTotal))

but the explicit call to str is slightly verbose. Consider re-phrasing such print statements in one of these ways:

print("blueTotal", blueTotal)
print(f'blueTotal {blueTotal}')

DRY

This repetitive code is an anti-pattern:

blueTotal = 0
greenTotal = 0
redTotal = 0
yellowTotal = 0

Please define

houses = 'blue green red yellow'.split()

and then you can use array access to perform "the same action" across all houses:

for house in houses:
    total[house] = 0

One could also assign total = collections.defaultdict(int), but that would be a horse of a different color. (https://docs.python.org/3/library/collections.html#collections.defaultdict)

global

The global keyword is usually not your friend, it leads to unfortunate coupling. Here, it is offering you a hint that you want to define a class, set totals to zero in the __init__() constructor, and then have places() access self.total[].

arg passing

This is a bit crazy:

    for competitors in competitorDetails:
        points()

Yes, you can treat competitors as an implicit argument by making it global, but there is absolutely no reason to, and the current code makes it extremely difficult for readers to understand what is going on. Please, please make competitors an explicit argument, passing it in with points(competitors).

formatting

Clearly this works:

print("blueTotal " + str(blueTotal))

but the explicit call to str is slightly verbose. Consider re-phrasing such print statements in one of these ways:

print("blueTotal", blueTotal)
print(f'blueTotal {blueTotal}')
Source Link
J_H
  • 42.3k
  • 3
  • 38
  • 157

#DRY This repetitive code is an anti-pattern:

blueTotal = 0
greenTotal = 0
redTotal = 0
yellowTotal = 0

Please define

houses = 'blue green red yellow'.split()

and then you can use array access to perform "the same action" across all houses:

for house in houses:
    total[house] = 0

One could also assign total = collections.defaultdict(int), but that would be a horse of a different color. (https://docs.python.org/3/library/collections.html#collections.defaultdict)

#global The global keyword is usually not your friend, it leads to unfortunate coupling. Here, it is offering you a hint that you want to define a class, set totals to zero in the __init__() constructor, and then have places() access self.total[].

#arg passing This is a bit crazy:

    for competitors in competitorDetails:
        points()

Yes, you can treat competitors as an implicit argument by making it global, but there is absolutely no reason to, and the current code makes it extremely difficult for readers to understand what is going on. Please, please make competitors an explicit argument, passing it in with points(competitors).

#formatting Clearly this works:

print("blueTotal " + str(blueTotal))

but the explicit call to str is slightly verbose. Consider re-phrasing such print statements in one of these ways:

print("blueTotal", blueTotal)
print(f'blueTotal {blueTotal}')