Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 165 - 2609_Logicode
P. 165

    ]

                               for day, number in DAYS:
                                   print(day, ":", number)

                           6.   Type the given program to find maximum and minimum number in a list and view
                               the output.

                               Code:
                               lst = []
                               num = int(input("How many numbers: "))

                               for n in range(num):
                                    numbers = int(input("Enter number "))
                                    lst.append(numbers)

                               print("Maximum element in the list is :", max(lst))
                               print("Minimum element in the list is :", min(lst))
                           7.   Type the given program to enter a number from the keyboard and then it will print:

                                    the sum of the digits of the number

                                    the reverses the number
                               Code:

                               sum = 0

                               rev = 0
                               number=int(input("Enter a number: "))

                               n = number
                               while (number):

                                    digit = number % 10
                                    sum += digit

                                    rev = rev * 10 + digit
                                    number //= 10

                               print("Reverse of number is : ",rev)
                               print ("Sum of digits of the number is : ",sum)

                                                                                                         Project Work  163

| 160 161 162 163 164 165 166 167 168 169 170 |