Computer Science, asked by ronit9726, 10 months ago

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.

Answers

Answered by Abhis506
0

ANS is Thermodynamics is you y

Attachments:
Answered by ridhimakh1219
0

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

Explanation:

Python program to count the number of times the digit '1' appears in the page number.

def count_pages(number_of_pages):

   total_number_of_ones = 0

   current_page = 1

   while current_page <= number_of_pages:

        page_number = str(current_page)

        total_number_of_ones += page_number.count('1')

        current_page  += 1

   return total_number_of_ones

   

print("Number of ones in pages:",count_pages(15))

print("Number of ones in pages:",count_pages(20))

print("Number of ones in pages:",count_pages(10))

Output

Number of ones in pages: 8            

Number of ones in pages: 12

Number of ones in pages: 2  

Similar questions