From 5c509c0d04b2cea4201fce476f9439b6c8f900e2 Mon Sep 17 00:00:00 2001 From: Artem Prigodsky Date: Sun, 20 Dec 2020 00:17:51 +0800 Subject: [PATCH] lession4 --- task1.py | 9 +++++++++ task2.py | 7 +++++++ task3.py | 3 +++ task4.py | 15 +++++++++++++++ task5.py | 11 +++++++++++ task6.py | 23 +++++++++++++++++++++++ task7.py | 10 ++++++++++ 7 files changed, 78 insertions(+) create mode 100644 task1.py create mode 100644 task2.py create mode 100644 task3.py create mode 100644 task4.py create mode 100644 task5.py create mode 100644 task6.py create mode 100644 task7.py diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..8d21722 --- /dev/null +++ b/task1.py @@ -0,0 +1,9 @@ +from sys import argv + + +hours = int(argv[1]) +pay_by_hour = int(argv[2]) +premium = int(argv[3]) + + +print((hours * pay_by_hour) + premium) diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..7d19fc1 --- /dev/null +++ b/task2.py @@ -0,0 +1,7 @@ +my_list = [300, 2, 12, 44, 1, 1, 4, 10, 7, 1, 78, 123, 55] + + +formatted_list = [item for key, item in enumerate(my_list) if key > 0 and item > my_list[key - 1]] + + +print(formatted_list) diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..7885272 --- /dev/null +++ b/task3.py @@ -0,0 +1,3 @@ +# 241 - потому что число 240 не попало бы в интервал :) +my_result = [item for item in range(20, 241) if item % 20 == 0 or item % 21 == 0] +print(my_result) diff --git a/task4.py b/task4.py new file mode 100644 index 0000000..3102430 --- /dev/null +++ b/task4.py @@ -0,0 +1,15 @@ +my_list = [2, 2, 2, 7, 23, 1, 44, 44, 3, 2, 10, 7, 4, 11] + + +def count_elements(list_items, value): + count = 0 + for item in list_items: + if item == value: + count += 1 + return count + + +result_list = [item for item in my_list if count_elements(my_list, item) == 1] + + +print(result_list) diff --git a/task5.py b/task5.py new file mode 100644 index 0000000..692b7f4 --- /dev/null +++ b/task5.py @@ -0,0 +1,11 @@ +from functools import reduce + + +def sum_elements(x, y): + return x + y + + +my_list = [item for item in range(100, 1001) if item % 2 == 0] +my_result = reduce(sum_elements, my_list) + +print(my_result) diff --git a/task6.py b/task6.py new file mode 100644 index 0000000..a2cb040 --- /dev/null +++ b/task6.py @@ -0,0 +1,23 @@ +from sys import argv +from itertools import count, cycle + +# итератор +counter = count(int(argv[1])) +stop = 40 +i = 0 +for item in counter: + print(item) + if i == stop: + break + i += 1 + + +# cycle +count_cycle = int(argv[1]) +cycle_items = cycle([1, 2, 3, 4, 5]) +i = 1 +for item in cycle_items: + print(item) + if i == count_cycle: + break + i += 1 diff --git a/task7.py b/task7.py new file mode 100644 index 0000000..9cea4b5 --- /dev/null +++ b/task7.py @@ -0,0 +1,10 @@ +def fact(n): + facts = [item for item in range(1, n + 1)] + start = 1 + for f in facts: + start *= f + yield start + + +for el in fact(10): + print(el)