Page 224 - Bilgisayar Bilimi | Kur 1
P. 224

Ekran Çıktısı

              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

              [3.4, 3.4, 3.4, 3.4, 3.4]
              [‘ABC’, ‘ABC’, ‘ABC’]
              [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30]

              [‘abc’, 22, 8.7, ‘abc’, 22, 8.7, ‘abc’, 22, 8.7]

                     Düşünelim/Deneyelim
                       * Operatörü stringler ile benzer sonuç verir.
                       >>> ‘abc’ * 3
                       ‘abcabcabc’

            10.9. Listedeki Değerlerin Ortalamasını Bulmak



              def main():
                     sum = 0.0
                     NUMBER _ OF _ ENTRIES = 5
                     numbers = []

                     print(“Please enter”, NUMBER _ OF _ ENTRIES, “numbers: “)
                     for i in range(0, NUMBER _ OF _ ENTRIES):
                            num = float(input(“Enter number “ + str(i) + “: “))
                            numbers += [num]
                            sum += num
                            print(end=”Numbers entered: “)

                            for num in numbers:
                            print(num, end=” “)
                            print() # Print newline
                            print(“Average:”, sum/NUMBER _ OF _ ENTRIES)
              main()

               Ekran Çıktısı

              Please enter 5 numbers:
              Enter number 0: 9.0
              Enter number 1: 3.5
              Enter number 2: 0.2
              Enter number 3: 100.0
              Enter number 4: 15.3

              Numbers entered: 9.0 3.5 0.2 100.0 15.3
              Average: 25.6
                                                                                                     223
   219   220   221   222   223   224   225   226   227   228   229