I'm working through Python Crash Course (end of Chapter 5). There is an example question to print the correct ending for the ordinal numbers 1 - 9, 1"st", 2"nd" etc. I expanded the example so it should work for any number, below.
How could this be written more concisely? What concepts could I look up? I'm an intermediate R user but quite new to Python. Thank you
nums = list(range(1, 50))
for i in nums:
if i % 10 == 1 and i % 100 != 11:
end = "st"
elif i % 10 == 2 and i % 100 != 12:
end = "nd"
elif i % 10 == 3 and i % 100 != 13:
end = "rd"
else:
end = "th"
print(f"{i}{end}")