I'm taking an Intro to Python course online and would like to solve this problem more efficiently.
The words 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th are called ordinal adjectives. Write a program which reads an integer x between 1 and 9 from input. The program should output the ordinal adjective corresponding to x. Hint: you don't need to have 9 separate cases; 4 is enough.
x = int(input())
if x == 1:
print("1st")
elif x == 2:
print("2nd")
elif x == 3:
print("3rd")
elif x == 4:
print("4th")
elif x == 5:
print("5th")
elif x == 6:
print("6th")
elif x == 7:
print("7th")
elif x == 8:
print("8th")
elif x == 9:
print("9th")
I can't figure out how to write this more efficiently in four lines. Does it involve lists? They have not taught lists or arrays yet.