Search code examples
pythonloopsgrammar

Python: grammar correct in a loop


"I was doing the follow exercise:

A gymnast can earn a score between 1 and 10 from each judge.

Print out a series of sentences, "A judge can give a gymnast _ points." Don't worry if your first sentence reads "A judge can give a gymnast 1 points." However, you get 1000 bonus internet points if you can use a for loop, and have correct grammar.

My code is this:

scores = (tuple(range(1,11)))
 
for score in scores:
   print (f'A judge can give a gymnast {score} points.')

And my output of course was:

  • A judge can give a gymnast 1 points.

  • A judge can give a gymnast 2 points.

  • A judge can give a gymnast 3 points.

  • A judge can give a gymnast 4 points.

  • A judge can give a gymnast 5 points.

  • A judge can give a gymnast 6 points.

  • A judge can give a gymnast 7 points.

  • A judge can give a gymnast 8 points.

  • A judge can give a gymnast 9 points.

  • A judge can give a gymnast 10 points.

The question is: How can I correct the grammar in my loop? I mean, when is "1 point" how can I make my loop to say "1 point" and not "1 points" and for the others scores maintain the "points"?


Solution

  • Heres another way of doing it. The answer above may(I don't know) be more efficient, in my opinion this is more readable for future developers.

    scores = (tuple(range(1,11)))
     
    for score in scores:
        if score == 1:
            print ('A judge can give a gymnast 1 point.')
        else:
            print (f'A judge can give a gymnast {score} points.')