【发布时间】:2020-11-24 12:36:19
【问题描述】:
我是 python 编程的新手。我正在尝试编写一个程序来查找列表中有多少个 9。enter image description here
seq = [1, 2, 3, 4, 9, 6, 8, 13, 9, 12, 19]
n = 0
t = []
y = len(seq)
for x in range (0, y-1):
if seq[x] == 9:
n += 1
t.append(x+1)
else: continue
print (n, "numbers of 9s are present at", t, "position" )'
输出:[5, 9] 位置出现 2 个 9
我如何编写程序以获取输出为“在 5 和 9 位置存在 2 个 9”。
【问题讨论】:
-
用
' and '.join(map(str, t))代替t怎么样?