-
Notifications
You must be signed in to change notification settings - Fork 445
ДЗ-1 #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ДЗ-1 #126
Changes from all commits
4d9a1dd
cf1e782
34465ad
85735ee
165f7af
ae5a720
d2cae79
3dd96e1
7489cfa
65160b1
3b4b48d
f72acda
fcd046c
899e6cb
1f009ac
52a9476
9132431
054ac61
360d67a
a90369b
cdab66b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,17 @@ | |
| # Для решения задачи не используйте встроенные функции и функции из модуля math. | ||
|
|
||
| def my_round(number, ndigits): | ||
| pass | ||
| number_temp1 = number*(10**ndigits) | ||
| number_temp_ostatok = number_temp1 % 1 | ||
| #print(number_temp_ostatok) | ||
| if number_temp_ostatok > 0.4: | ||
| number_add = 1 - number_temp_ostatok | ||
| round_number = number + (number_add/(10**ndigits)) | ||
| else: | ||
| number_add = number_temp_ostatok - 1 | ||
| round_number = number - (number_add/(10**ndigits)) | ||
| #print(round_number) | ||
| return round_number | ||
|
|
||
|
|
||
| print(my_round(2.1234567, 5)) | ||
|
|
@@ -20,7 +30,20 @@ def my_round(number, ndigits): | |
| # !!!P.S.: функция не должна НИЧЕГО print'ить | ||
|
|
||
| def lucky_ticket(ticket_number): | ||
| pass | ||
| ticket_number_map = list(map(int, str(ticket_number))) | ||
| try: | ||
| ticket_part_1 = ticket_number_map[0] + ticket_number_map[1] + ticket_number_map[2] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Поговорим про exception'ы сегодня. Нельзя их так использовать |
||
| except IndexError: | ||
| pass | ||
| try: | ||
| ticket_part_2 = ticket_number_map[3]+ ticket_number_map[4]+ticket_number_map[5] | ||
| except IndexError: | ||
| pass | ||
| try: | ||
| result = ticket_part_1 == ticket_part_2 | ||
| return (result) | ||
| except: | ||
| pass | ||
|
|
||
|
|
||
| print(lucky_ticket(123006)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,12 @@ | |
| # Первыми элементами ряда считать цифры 1 1 | ||
|
|
||
| def fibonacci(n, m): | ||
| pass | ||
| a = 0 | ||
| fibo = [1, 1] | ||
| while a< m: | ||
| fibo.append(fibo[0+a]+fibo[1+a]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. хорошо. но когда делаешь a += 1 лучше исопльзовать цикл for, который это делает автоматом - для избежания ошибок и понятнее) |
||
| a+=1 | ||
| return fibo[n:m] | ||
|
|
||
| # Задача-2: | ||
| # Напишите функцию, сортирующую принимаемый список по возрастанию. | ||
|
|
@@ -12,14 +17,30 @@ def fibonacci(n, m): | |
|
|
||
|
|
||
| def sort_to_max(origin_list): | ||
| pass | ||
| a = origin_list | ||
| for i in range(len(a),0,-1): | ||
| for n in range(1,i): | ||
| if a[n-1] > a[n]: | ||
| an = a[n-1] | ||
| a[n-1] = a[n] | ||
| a[n] = an | ||
| return a | ||
|
|
||
|
|
||
| sort_to_max([2, 10, -12, 2.5, 20, -11, 4, 4, 0]) | ||
|
|
||
| # Задача-3: | ||
| # Напишите собственную реализацию стандартной функции filter. | ||
| # Разумеется, внутри нельзя использовать саму функцию filter. | ||
|
|
||
| def myFilter(listed, x): | ||
| listed_res = [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут имелось в виду передать функцию filter(lambda x: x == 0, [1, 2, 3]) например |
||
| for i in listed: | ||
| if i == x: | ||
| listed_res.append(i) | ||
| else: | ||
| pass | ||
| return listed_res | ||
|
|
||
| # Задача-4: | ||
| # Даны четыре точки А1(х1, у1), А2(x2 ,у2), А3(x3 , у3), А4(х4, у4). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,27 @@ | |
| # квадратами элементов исходного списка | ||
| # [1, 2, 4, 0] --> [1, 4, 16, 0] | ||
|
|
||
| start_list = [1,2,4,0] | ||
| result_list = [i**2 for i in start_list] | ||
| #print(start_list) | ||
| #print(result_list) | ||
|
|
||
| # Задание-2: | ||
| # Даны два списка фруктов. | ||
| # Получить список фруктов, присутствующих в обоих исходных списках. | ||
|
|
||
| first_list = ['orange','apple', 'ananas', 'pears', 'banana'] | ||
| second_list = ['orange', 'banana','apple', 'ananas'] | ||
| result_list = [i for i in first_list and second_list] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это работает непраивльно |
||
| print(result_list) | ||
|
|
||
| # Задание-3: | ||
| # Дан список, заполненный произвольными числами. | ||
| # Получить список из элементов исходного, удовлетворяющих следующим условиям: | ||
| # + Элемент кратен 3 | ||
| # + Элемент положительный | ||
| # + Элемент не кратен 4 | ||
|
|
||
| start_list = [1,2,3,4,5,6,1,2,3,4, -1] | ||
| result_list = [i for i in start_list if i > 0 and i%3 ==0 and i%4 !=0] | ||
| #print(result_list) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,11 @@ | |
| 'qHFjvihuNGEEFsfnMXTfptvIOlhKhyYwxLnqOsBdGvnuyEZIheApQGOXWeXoLWiDQNJFa'\ | ||
| 'XiUWgsKQrDOeZoNlZNRvHnLgCmysUeKnVJXPFIzvdDyleXylnKBfLCjLHntltignbQoiQ'\ | ||
| 'zTYwZAiRwycdlHfyHNGmkNqSwXUrxGc' | ||
|
|
||
| import re | ||
| split_line = re.split(r'[A-Z]', line) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут у вас на выходе будет много пустых элементов. Разбирали на вебинаре, посмотри) |
||
| final_line = list(filter(None, split_line)) | ||
| #print(split_line) | ||
| print(final_line) | ||
|
|
||
| # Задание-2: | ||
| # Вывести символы в верхнем регистре, слева от которых находятся | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,25 @@ | |
| # Напишите скрипт, создающий директории dir_1 - dir_9 в папке, | ||
| # из которой запущен данный скрипт. | ||
| # И второй скрипт, удаляющий эти папки. | ||
| import os, time, shutil | ||
| #print(os.getcwd()) | ||
| number = 1 | ||
| number_1 = 1 | ||
| while number < 10: | ||
| os.mkdir('./dir_'+str(number), mode=511, dir_fd=None) | ||
| number += 1 | ||
| time.sleep(10) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. зачем тут sleep? директория не успевает создаться?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. успевает, вставлял sleep для теста (нагляднее), забыл закоментить при сдаче :) |
||
| while number_1 <10: | ||
| os.removedirs('./dir_'+str(number_1)) | ||
| number_1 += 1 | ||
|
|
||
| # Задача-2: | ||
| # Напишите скрипт, отображающий папки текущей директории. | ||
|
|
||
| print(list(os.listdir('./'))) | ||
|
|
||
| # Задача-3: | ||
| # Напишите скрипт, создающий копию файла, из которого запущен данный скрипт. | ||
| shutil.copy(r'./lesson5.py', r'./lesson5_copy.py') | ||
| time.sleep(10) | ||
| os.remove(r'./lesson5_copy.py') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import os | ||
|
|
||
| def change_dir(curr_dir): | ||
| os.chdir(curr_dir) | ||
| def create_folder_func(curr_dir, number): | ||
| os.mkdir(str(number), mode=511, dir_fd=None) | ||
| def remove_folder_func(curr_dir, number_1): | ||
| os.removedirs(str(number_1)) | ||
| def look_func(curr_dir): | ||
| print(list(os.listdir(curr_dir))) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,42 @@ | |
| # Для решения данной задачи используйте алгоритмы из задания easy, | ||
| # оформленные в виде соответствующих функций, | ||
| # и импортированные в данный файл из easy.py | ||
|
|
||
| # немного не успел доделать | ||
| import hw05_easy_func, os | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. прикольно) но лучше импортами в одну строчку не увлекаться для читабельности. Здесь к месту, хорошо) |
||
| curr_dir= os.getcwd() | ||
| curr_dir1= curr_dir | ||
| print('Вы сейчас находитесь в директории:', curr_dir) | ||
| def start_func(curr_dir): | ||
| print('1) Перейти в папку, 2) Посмотреть сождержимое текущей папки, 3) Удалить папку, 4) Создать папку, 5) Вернуться в домашнюю директорию, 6) Выход') | ||
| inputed = int(input('')) | ||
| #print(inputed) | ||
| if inputed == 1: | ||
| print(hw05_easy_func.look_func(curr_dir)) | ||
| curr_dir = hw05_easy_func.change_dir(input()) | ||
| print(curr_dir) | ||
| return curr_dir, start_func(curr_dir) | ||
| elif inputed == 2: | ||
| look = hw05_easy_func.look_func(curr_dir) | ||
| #print(look) | ||
| start_func(curr_dir) | ||
| elif inputed == 3: | ||
| print('Введите имя папки которую необходимо удалить') | ||
| folder_name = input('') | ||
| delete = hw05_easy_func.remove_folder_func(curr_dir, folder_name) | ||
| start_func(curr_dir) | ||
| elif inputed == 4: | ||
| print('Введите имя папки которую необходимо создать') | ||
| folder_name = input('') | ||
| create = hw05_easy_func.create_folder_func(curr_dir, folder_name) | ||
| start_func(curr_dir) | ||
| elif inputed == 5: | ||
| curr_dir = curr_dir1 | ||
| start_func(curr_dir) | ||
| elif inputed == 6: | ||
| pass | ||
| else: | ||
| print('Введено некорректное число') | ||
| start_func(curr_dir) | ||
|
|
||
| start_func(curr_dir) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hard way :D