Home > Problem, Projects/Experiments, Python > Python Project: Pluralise a Word

Python Project: Pluralise a Word




Python: Pluralise a Word


Loop through a dictionary and pluralise a word

One of Python Exercises on @PyBites codechalleng is to loop through a given dictionary of people and the number of games they’ve won then print out the users name and how many games they’ve won in the following format: “sara has won n games” and pluralise the word game to suit the number of games won.

we assume the dictionary is
games_won = dict={‘sara’:0, ‘bob’:1, ‘tim’:5, ‘julian’:3, ‘jim’:1}



The Code:



games_won ={‘sara’:0, ‘bob’:1, ‘tim’:5, ‘julian’:3, ‘jim’:1}
def print_game_stats(games_won):

for key,val in games_won.items():

print(“{} has won {}{p}”.format(key, val,p=” game” if val ==1 else ” games” ))

print_game_stats(games_won)









Follow me on Twitter..

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s