MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getOrdIndicator

Function getOrdIndicator

src/gamesbyexample/lostkitty.py:85–108  ·  view source on GitHub ↗

Returns the "ordinal indicator" of number, e.g. 'st' for 1 and 'rd' for 23, because we write them as "1st" and "23rd".

(number)

Source from the content-addressed store, hash-verified

83
84
85def getOrdIndicator(number):
86 """Returns the "ordinal indicator" of number, e.g. 'st' for 1 and
87 'rd' for 23, because we write them as "1st" and "23rd"."""
88 lastDigit = str(number)[-1]
89
90 if len(str(number)) >= 2:
91 secondToLastDigit = str(number)[-2]
92 else:
93 secondToLastDigit = ''
94
95 if secondToLastDigit + lastDigit == '11':
96 return 'th'
97 elif secondToLastDigit + lastDigit == '12':
98 return 'th'
99 elif secondToLastDigit + lastDigit == '13':
100 return 'th'
101 elif lastDigit == '1':
102 return 'st'
103 elif lastDigit == '2':
104 return 'nd'
105 elif lastDigit == '3':
106 return 'rd'
107 else:
108 return 'th'
109
110
111def displayMap(playerx, playery, visitedIntersections):

Callers 1

displayMapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected