1

I am making a web application in flask and I want to format the post votes better.

Instead of it saying "1 votes" I want it to say "1 vote" and so on.

My attempt:

def format_post_votes(post):

    output = ''

    if post.votes == 0 or post.votes > 1:
        output = 's'
    else:
        output = ''

    return f'{post.votes}{output}'

Is there a more efficient way to do this?..

martineau
  • 119,623
  • 25
  • 170
  • 301
docyoda
  • 1
  • 1
  • 5

1 Answers1

2

You could simplify it to:

def format_post_votes(post):
    return f'{post.votes}{"" if post.votes == 1 else "s"}'
Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45