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
  • 112,593
  • 23
  • 157
  • 280
docyoda
  • 1
  • 1
  • 4

1 Answers1

1

You could simplify it to:

def format_post_votes(post):
    return f'{post.votes}{"" if post.votes == 1 else "s"}'
Solomon Ucko
  • 3,994
  • 2
  • 20
  • 39