Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

442
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda