From 4b19950f2837d8d9fb4435ab10a53a5590b5b8b9 Mon Sep 17 00:00:00 2001 From: "d.zashivalov" Date: Wed, 13 Apr 2022 11:54:01 +0300 Subject: [PATCH] Lesson_4 --- lesson_4/4-1.py | 13 +++++++++++++ lesson_4/4-2.py | 4 ++++ lesson_4/4-3.py | 1 + lesson_4/4-4.py | 3 +++ lesson_4/4-5.py | 9 +++++++++ lesson_4/4-6.py | 17 +++++++++++++++++ lesson_4/4-7.py | 15 +++++++++++++++ 7 files changed, 62 insertions(+) create mode 100644 lesson_4/4-1.py create mode 100644 lesson_4/4-2.py create mode 100644 lesson_4/4-3.py create mode 100644 lesson_4/4-4.py create mode 100644 lesson_4/4-5.py create mode 100644 lesson_4/4-6.py create mode 100644 lesson_4/4-7.py diff --git a/lesson_4/4-1.py b/lesson_4/4-1.py new file mode 100644 index 0000000..a22efc0 --- /dev/null +++ b/lesson_4/4-1.py @@ -0,0 +1,13 @@ +import sys +from sys import argv + + +def z_func(): + try: + script_name, h_param, ph_param, b_param = argv + return (float(h_param) * float(ph_param)) + float(b_param) + except ValueError: + return 0 + + +print(z_func()) diff --git a/lesson_4/4-2.py b/lesson_4/4-2.py new file mode 100644 index 0000000..871212b --- /dev/null +++ b/lesson_4/4-2.py @@ -0,0 +1,4 @@ +src_list = [300, 2, 12, 44, 1, 1, 4, 10, 7, 1, 78, 123, 55] +trg_list = [num for i, num in enumerate(src_list[1:]) if num > src_list[i]] +print(src_list) +print(trg_list) \ No newline at end of file diff --git a/lesson_4/4-3.py b/lesson_4/4-3.py new file mode 100644 index 0000000..f41ada1 --- /dev/null +++ b/lesson_4/4-3.py @@ -0,0 +1 @@ +print(f'{[el for el in range(20, 241) if el % 20 == 0 or el % 21 == 0]}') diff --git a/lesson_4/4-4.py b/lesson_4/4-4.py new file mode 100644 index 0000000..71ac261 --- /dev/null +++ b/lesson_4/4-4.py @@ -0,0 +1,3 @@ +my_list = [2, 2, 2, 7, 23, 1, 44, 44, 3, 2, 10, 7, 4, 11] +my_new_list = [el for el in my_list if my_list.count(el) < 2] +print(my_new_list) \ No newline at end of file diff --git a/lesson_4/4-5.py b/lesson_4/4-5.py new file mode 100644 index 0000000..3124b68 --- /dev/null +++ b/lesson_4/4-5.py @@ -0,0 +1,9 @@ +from functools import reduce + + +def my_func(el_p, el): + return el_p * el + + +print(f'Список четных значений {[el for el in range(99, 1001) if el % 2 == 0]}') +print(f'Результат перемножения всех элементов списка {reduce(my_func, [el for el in range(99, 1001) if el % 2 == 0])}') diff --git a/lesson_4/4-6.py b/lesson_4/4-6.py new file mode 100644 index 0000000..e25d245 --- /dev/null +++ b/lesson_4/4-6.py @@ -0,0 +1,17 @@ +from itertools import count + +for el in count(int(input('Введите стартовое число: '))): + print(el) + if el >= 10: + break + + +from itertools import cycle + +c = 0 +my_list = [123, False, 'XXX', None] +for el in cycle(my_list): + print(el) + c += 1 + if c >= 10: + break diff --git a/lesson_4/4-7.py b/lesson_4/4-7.py new file mode 100644 index 0000000..8b77b59 --- /dev/null +++ b/lesson_4/4-7.py @@ -0,0 +1,15 @@ +from itertools import count +from math import factorial + +def fact(): + for el in count(1): + yield factorial(el) + +gen = fact() +x = 0 +for i in gen: + if x < 15: + print(i) + x += 1 + else: + break \ No newline at end of file