Page 51 - ipp11
P. 51

(c)  n=int (input("enter the limit"))

                   print("reverse numbers are as follows")
                   for i in range(n,0,-1):
                        print(i)
            37.  (a)  Write a menu-driven Python program to perform the following basic string operations:    [5]
                    (i)  Convert to uppercase
                    (ii)  Convert to lowercase
                   (iii)  Count characters
                   (iv)  Reverse string
                    (v)  Exit
                                                           Or
                (b)  Write a menu-driven Python program that manages a Library Book Tracking System using a dictionary. The
                   program should allow users to add books, update no. of books, issue books and display books.
                    The menu should display the following options:
                    (i)  Add a New Book
                    (ii)  Update Number of Copies
                   (iii)  Issue a Book (reduce copy count)
                   (iv)  Display All Books (sorted by title)
                    (v)  Exit the program

           Ans.  (a)  while True:
                        print("\n1. Uppercase\n2. Lowercase\n3. Character Count\n4. Reverse\
                   n5. Exit")
                   choice = int(input("Enter your choice: "))
                   if choice == 5:
                        break
                   s = input("Enter a string: ")
                   if choice == 1:
                        print(s.upper())
                   elif choice == 2:
                        print(s.lower())
                   elif choice == 3:
                        print("Length:", len(s))
                   elif choice == 4:
                        print("Reversed:", s[::-1])
                   else:
                        print("Invalid choice")
                                                           Or
                (b)  library = {}

                   while True:
                        print("\n===== Library Menu =====")
                        print("a. Add a New Book")
                        print("b. Update Number of Copies")
                        print("c. Issue a Book")
                        print("d. Display All Books (Sorted by Title)")
                        print("e. Exit")
                   choice = input("Enter your choice (a-f): ").lower()
                   if choice == 'a':
                        book = input("Enter book title: ")
                        if book in library:
                              print("Book already exists in the library.")


                                                              M.21
   46   47   48   49   50   51   52   53   54   55   56