记录一下我的学习~~
**
【Python 3.7】序数:序数表示位置,如 1st和 2nd。大多数序数都以 th结尾,只有 1、2和 3 例外。
**
题目:
序数:序数表示位置,如 1st和 2nd。大多数序数都以 th结尾,只有 1、2和 3 例外。
在一个列表中存储数字 1~9。
遍历这个列表。
在循环中使用一个 if-elif-else 结构,以打印每个数字对应的序数。输出内容
应为 1st 、 2nd 、 3rd 、 4th 、 5th 、 6th 、 7th 、 8th 和 9th , 但每个序数都独占一行。
numbers=list(range(1,10))
for number in numbers:
if number==1:
print("1st")
elif number==2:
print("2nd")
elif number==3:
print("3rd")
else:
print(str(number)+'th')
博客围绕 Python 3.7 序数展开,序数表示位置,多数以 th 结尾,1、2、3 例外。给出题目,要求在列表存 1 - 9 数字,遍历列表,用 if - elif - else 结构打印对应序数,使每个序数独占一行。
3920

被折叠的 条评论
为什么被折叠?



