I'm working in Python 3, Windows 10, PyCharm.
I'm building a small program that lets you input your age and returns "Happy {age}{termination, eg: st, nd}!"
The thing is that I want to somehow avoid the situation where you will write your age as 1041 and it'll say "Happy 1041th!". So I used list(range(21, 1001, 10))
for the termination "st", for instance. However, I'd like to be able to use infinite
instead of 1001. If I use math.inf
, that's a float and it's not accepted in my code. Also, I can't convert it to int.
I'm thinking of using a n
number that should be higher than say, 100, and have list(range(21, n, 10))
, but I'm too much of a beginner to know how to do that.
Thanks for the help. Here's my code:
age = int(input('Type age: '))
if int(age) == 1:
term = 'st'
elif int(age) == 2:
term = 'nd'
elif int(age) == 3:
term = 'rd'
elif int(age) in list(range(21, 1001, 10)):
term = 'st'
elif int(age) in list(range(22, 1002, 10)):
term = 'nd'
elif int(age) in list(range(23, 1003, 10)):
term = 'rd'
else:
term = 'th'
if int(age) >= 130:
print("C'mon! you can't be THAT old, you geezer!\nStill, here you go:")
message = f"Happy {age}{term} birthday!"
print(message)