Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

440
Vistas
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"?

over 4 years ago · Santiago Trujillo
5 Respuestas
Responde la pregunta

0

Conditionally add the s to the string:

print(f'A judge can give a gymnast {score} point{"s" if score > 1 else ""}.')
over 4 years ago · Santiago Trujillo Denunciar

0

All you'll need is an if statement to check the score

scores = (tuple(range(1,11)))
 
for score in scores:
   if (score == 1):
       print (f'A judge can give a gymnast {score} point.')
   else:
       print (f'A judge can give a gymnast {score} points.')
over 4 years ago · Santiago Trujillo Denunciar

0

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.')
over 4 years ago · Santiago Trujillo Denunciar

0

I conclude from the simplicity of this problem, that you are rather new to Python and Programming in general.

You should take a look at fundamental-concepts like flow-control and finding a solution shouldn't be hard at all.

https://docs.python.org/3/tutorial/controlflow.html

But still - to give you a concrete answer to the question, you could simply add an if-statement to your loop like this:

scores = (tuple(range(1,11)))
 
for score in scores: 
   output = f'A judge can give a gymnast {score} point'
   if score > 1: 
      output += "s"
   print(f"{output}.")
over 4 years ago · Santiago Trujillo Denunciar

0

A straight-forward way would be to use the python string format to conditionally render the s

print(f'A judge can give a gymnast {score} point{"s" if score > 1 else ""}.')
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda