Answer

Answer

t.me/python_tesst

Ответ:

0

1

2

3

5

15

25

2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 25.0 2

-0.5

-3.0

Объяснение:

Модуль itertools стандартизирует основной набор быстрых эффективных по памяти инструментов, которые полезны сами по себе или в связке с другими инструментами. Вместе они формируют «алгебру итераторов», которая позволяет лаконично и эффективно создавать специализированные инструменты на чистом Python. Модуль itertools находится в стандартной библиотеке Python. Модуль представляет count(), который возвращает равномерно распределенные значения, начиная с числа, указанного в аргументе start. По умолчанию start равен 0, а step -1. Шаг также может быть нецелым значением. Эта функция вернет бесконечный итератор.

Код:

import itertools
c=itertools.count()
#next() function returns next item in the iterator.By default starts with number 0 and increments by 1.
print (next(c))#Output:0
print (next(c))#Output:1
print (next(c))#Output:2
print (next(c))#Output:3


#Returns an infinite iterator starting with number 5 and incremented by 10. The values in the iterator are accessed by next()
c1=itertools.count(5,10)
print(next(c1))#Output:5
print(next(c1))#Output:10
print(next(c1))#Output:15


#accessing values in the iterator using for loop.step argument can be float values also.
c2=itertools.count(2.5,2.5)
for i in c2:
    #including terminating condition, else loop will keep on going.(infinite loop)
    if i>25:
        break
    else:
        print (i,end=" ") #Output:2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 25.0
        

#step can be negative numbers also.negative numbers count backwards.
c3=itertools.count(2,-2.5)
print (next(c3))#Output:2
print (next(c3))#Output:-0.5
print (next(c3))#Output:-3.0



Report Page