Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions iterator1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 6.a итератор, генерирующий целые числа, начиная с указанного
from sys import argv
import itertools as itr

start = int(argv[1])

for el in itr.count(start):
if el > 1000:
print('стоп машина!')
break
else:
print(el)
12 changes: 12 additions & 0 deletions iterator2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 6.b итератор, повторяющий элементы некоторого списка, определенного заранее
import itertools as itr

my_list = [2, 65, 3, 5, 8, 14, 28, 38, 53, 46, 31, 2, 4]

с = 0
for el in itr.cycle(my_list):
if с > 100:
print('Стоп машина!')
break
print(el)
с += 1
6 changes: 6 additions & 0 deletions salary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# task 1
from sys import argv
script_name, production, rate, prize = argv

salary = int(production) * int(rate) + int(prize)
print(salary)
4 changes: 4 additions & 0 deletions task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_list = [2, 65, 3, 5, 8, 14, 28, 38, 53, 46, 31, 2, 4]
print('имходный список:', my_list)
new_list = [el for i, el in enumerate(my_list) if my_list[i] > my_list[i-1]]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Первый элемент сравнивается с последним словом - бага!

print('Сгенерированный список:', new_list)
1 change: 1 addition & 0 deletions task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print([el for el in range(20, 241) if el % 20 == 0 or el % 21 == 0])
3 changes: 3 additions & 0 deletions task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
my_list = [2, 2, 2, 7, 23, 1, 44, 44, 3, 2, 10, 7, 4, 11]
new_list = [el for i, el in enumerate(my_list) if my_list.count(el) == 1]
print(new_list)
5 changes: 5 additions & 0 deletions task5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from functools import reduce

new_list = [el for el in range(100, 1001) if el % 2 == 0]
result = reduce((lambda x, y: x * y), new_list)
print(result)
8 changes: 8 additions & 0 deletions task7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def fact(n):
result = 1
for i in range(1, n + 1):
result *= i
yield result

for el in fact(5):
print(el)