Create a function countPages(x) that takes the number of pages of a book as an argument and counts the number of times the digit ‘1’ appears in the page number.

6 views

1 Answers

Answer:

def countPages(num):

total = 0

i = 1

while i<=num:

page_no = str(i)

total + = page_no.count(‘1’)

i+ = l

return total

6 views