Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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].
I am curious how to remove [] from the output, f string, or something?
I want the output to look something like "From number 1 to {n}, digit {c} is shown in numbers: {where(n, c)}.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

1 10 11 12 13 14 15 16 17 18 19 21
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading