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
49 changes: 49 additions & 0 deletions lesson02/home_work/hw02_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,70 @@
# если такой корень вообще можно извлечь
# Пример: Дано: [2, -5, 8, 9, -25, 25, 4] Результат: [3, 5, 2]

import math

a = [2, -5, 8, 9, -25, 25, 4]
b = []

for i in a:
if i > 0 and math.sqrt(i) % 1 == 0:
b.append(math.sqrt(i))
print(b)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

хорошо



# Задача-2: Дана дата в формате dd.mm.yyyy, например: 02.11.2013.
# Ваша задача вывести дату в текстовом виде, например: второе ноября 2013 года.
# Склонением пренебречь (2000 года, 2010 года)

day = {'01': "первое", '02': "второе", '03': 'третье', '04': "четвертое", '05': "пятое", '06': "шестое", '07': "седьмое",
'08': 'восьмое', '09': "девятое", '10': "десятое", '11': "одиннадцатое", '12': "двенадцатое", '13': "тринадцатое",
'14': "четырнадцатое", '15': "пятнадцатое", '16': "шестнядцатое", '17': "семнадцатое", '18': "восемнадцатое",
'19': "девятнадцатое", '20': "двадцатое", '21': "двадцать первое", '22': "двадцать второе", '23': "двадцать третье",
'24': "двадцать четвертое", '25': "двадцать пятое", '26': "двадцать шестое", '27': "двадцать седьмое",
'28': "двадцать восьмое", '29': "двадцать девятое", '30': "тридцатое", '31': "тридцать первое"}
month = {"01": "января", "02": "февраля", "03": "марта", "04": "апреля", "05": "мая", "06": "июня",
"07": "июля", "08": "августа", "09": "сентября", "10": "октября", "11": "ноября", "12": "декабря"}

date = input('Введите дату в формате dd.mm.yyyy ')
new_date = date.split('.')
print('Вы ввели {} {} {}'.format(day[new_date[0]], month[new_date[1]], new_date[2]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

все верно


# Задача-3: Напишите алгоритм, заполняющий список произвольными целыми числами
# в диапазоне от -100 до 100. В списке должно быть n - элементов.
# Подсказка:
# для получения случайного числа используйте функцию randint() модуля random

import random

lst = []
n = random.randint(-100, 100)
i = -101

while i < n:
lst.append(random.randint(-100, 100))
i += 1
print(lst)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

отлично


# Задача-4: Дан список, заполненный произвольными целыми числами.
# Получите новый список, элементами которого будут:
# а) неповторяющиеся элементы исходного списка:
# например, lst = [1, 2, 4, 5, 6, 2, 5, 2], нужно получить lst2 = [1, 2, 4, 5, 6]
# б) элементы исходного списка, которые не имеют повторений:
# например, lst = [1 , 2, 4, 5, 6, 2, 5, 2], нужно получить lst2 = [1, 4, 6]

lst = [1, 2, 4, 5, 6, 2, 5, 2]
lst2 = []
lst3 = []

#a
lst2 = set(lst)
print(lst2)

#b
for i in lst:
if lst.count(i) == 1:
lst3.append(i)
print(lst3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

и с этим разобрались, вижу множества хорошо изучили

18 changes: 15 additions & 3 deletions lesson03/home_work/hw03_easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
# Для решения задачи не используйте встроенные функции и функции из модуля math.

def my_round(number, ndigits):
pass
round_number = 10 ** ndigits
number_2 = int(number * round_number + 0.5)
scale_number = number_2 / round_number
return scale_number

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

хорошо


print(my_round(2.1234567, 5))
Expand All @@ -20,9 +23,18 @@ def my_round(number, ndigits):
# !!!P.S.: функция не должна НИЧЕГО print'ить

def lucky_ticket(ticket_number):
pass
lst_1 = list(str(ticket_number))
lst_2 = []
lst_2.append(lst_1[3:6])
del lst_1[3:6]
lst_1 = [int(i) for i in lst_1]
lst_2 = [int(el) for el in lst_2]
if lst_1[0] + lst_1[1] + lst_1[2] == lst_2[0] + lst_2[1] + lst_2[2]:
print('У вас счастливый билет!')
else:
print('У вас обычный билет')
# Не могу понять в чем ошибка, логика программы вроде бы правильная :(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

отлично. задействовали срезы



print(lucky_ticket(123006))
print(lucky_ticket(12321))
print(lucky_ticket(436751))
13 changes: 13 additions & 0 deletions lesson04/home_work/hw04_easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
# квадратами элементов исходного списка
# [1, 2, 4, 0] --> [1, 4, 16, 0]

lst1 = [1, 2, 4, 0]
lst2 = [el ** 2 for el in lst1]
print(lst2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

хорошо

# Задание-2:
# Даны два списка фруктов.
# Получить список фруктов, присутствующих в обоих исходных списках.

lst1 = ['яблоко', 'груша', 'слива', "вишня", "персик"]
lst2 = ['ананас', "виноград", "яблоко", "персик", "малина"]
lst3 = [el for el in lst1 if el in lst2]
print(lst3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

отлично

# Задание-3:
# Дан список, заполненный произвольными числами.
# Получить список из элементов исходного, удовлетворяющих следующим условиям:
# + Элемент кратен 3
# + Элемент положительный
# + Элемент не кратен 4

lst = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
lst2 = [el for el in lst if not(el % 3) and el > 0 and el % 4]
print(lst2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

хорошо