Page 507 - ComputerScience_Class_11
P. 507

Program 7.py

                  File  Edit  Format   Run   Options   Window     Help

                  n = int(input("Enter a number: "))
                  c=n
                  inc = False
                  dec = False
                  while n > 9:
                      d1 = n % 10
                      d2 = (n // 10) % 10
                      if d1 > d2:
                          inc = True
                      elif d1 < d2:
                          dec = True
                      n //= 10
                  if inc and dec:
                      print(c," is a Bouncy Number")
                  else:
                      print(c,"is not a Bouncy Number")




                     Output

                  Enter a number: 8598

                  8598  is a Bouncy Number




                 Program 8: Write a program to search for a book in a list of books. If the book is found, the loop stops using break.

                     Program 8.py

                  File  Edit  Format   Run   Options   Window     Help

                  library_books = ['Harry Potter', 'Python Programming', 'Data Science', 'AI for Everyone']
                  #book_to_find = 'Python Programming'
                  book_to_find = input('Enter the name of a book: ')
                  for book in library_books:
                      if book == book_to_find:
                          print('Book', book_to_find, 'found!')
                          break
                  else:
                      print('Book', book_to_find, 'is not available in the library.')









                                                                                                    Flow of Control  505
   502   503   504   505   506   507   508   509   510   511   512