[英]Where can c(digit) be found in n(number)
n = int(input("Unesite n: "))
c = int(input("Unesite c: "))
def where(n, c):
where = []
for i in range(1, n + 1):
dig = i
while dig > 0:
if dig % 10 == c:
where.append(i)
break
dig //= 10
print(where)
The answer to this question is probably stupid but... :/ For input n=22 and c=1 output is [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21] .这个问题的答案可能很愚蠢,但是......:/对于输入 n=22 和 c=1 output 是[1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21] . I am curious how to remove [] from the output, f string, or something?
我很好奇如何从 output、f 字符串或什么中删除 []? I want the output to look something like "From number 1 to {n}, digit {c} is shown in numbers: {where(n, c)}.
我希望 output 看起来像“从数字 1 到 {n},数字 {c} 以数字显示:{where(n, c)}。
def where(n, c):
where = []
for i in range(1, n + 1):
dig = i
while dig > 0:
if dig % 10 == c:
where.append(i)
break
dig //= 10
for e in where:
print(e, end= " ")
then the output will be那么 output 将是
1 10 11 12 13 14 15 16 17 18 19 21
here is another solution:这是另一个解决方案:
def where(n, c):
where = []
for i in range(1, n + 1):
dig = i
while dig > 0:
if dig % 10 == c:
where.append(i)
break
dig //= 10
print(str(where)[1:-1])
n = 22
c = 1
where(n, c)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.