From a2ee02012510d1d0d233f262157f7a4968b7f427 Mon Sep 17 00:00:00 2001 From: "Serebryakov.AO" Date: Tue, 13 Apr 2021 00:16:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=204-=D0=B3=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iterator1.py | 12 ++++++++++++ iterator2.py | 12 ++++++++++++ salary.py | 6 ++++++ task2.py | 4 ++++ task3.py | 1 + task4.py | 3 +++ task5.py | 5 +++++ task7.py | 8 ++++++++ 8 files changed, 51 insertions(+) create mode 100644 iterator1.py create mode 100644 iterator2.py create mode 100644 salary.py create mode 100644 task2.py create mode 100644 task3.py create mode 100644 task4.py create mode 100644 task5.py create mode 100644 task7.py diff --git a/iterator1.py b/iterator1.py new file mode 100644 index 0000000..3b2532f --- /dev/null +++ b/iterator1.py @@ -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) diff --git a/iterator2.py b/iterator2.py new file mode 100644 index 0000000..4b01114 --- /dev/null +++ b/iterator2.py @@ -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 diff --git a/salary.py b/salary.py new file mode 100644 index 0000000..69a75dd --- /dev/null +++ b/salary.py @@ -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) diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..4fcfbb0 --- /dev/null +++ b/task2.py @@ -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]] +print('Сгенерированный список:', new_list) diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..3fb541f --- /dev/null +++ b/task3.py @@ -0,0 +1 @@ +print([el for el in range(20, 241) if el % 20 == 0 or el % 21 == 0]) diff --git a/task4.py b/task4.py new file mode 100644 index 0000000..accc7ea --- /dev/null +++ b/task4.py @@ -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) diff --git a/task5.py b/task5.py new file mode 100644 index 0000000..49360de --- /dev/null +++ b/task5.py @@ -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) diff --git a/task7.py b/task7.py new file mode 100644 index 0000000..3a8d939 --- /dev/null +++ b/task7.py @@ -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) \ No newline at end of file