Dcoder icon

Ordinal Representation @ Dcoder

By Lochard | As a newbie programmer | 8 May 2023


Problem: Numbers can be represented in cardinal form or ordinal form.

Cardinal Form : 1, 2, 3, 4, 5, 6, etc.

Ordinal Form : 1st, 2nd, 3rd, 4th, 5th, 6th, etc.

You will be given cardinal form of a digit. You have to print its ordinal form.

Input: A single digit positive digit.

Output: Print the ordinal from of the digit.

Constraints: 1 ≤ N ≤ 9

Sample Input: 3

Sample Output: 

3rd

n = int(input())
print(str(n) + ('st' if n == 1 else 'nd' if n < 3 else 'rd' if n == 3 else'th'))

How do you rate this article?

4


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.