-
Notifications
You must be signed in to change notification settings - Fork 0
lesson 6 #8
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
Open
serg0761
wants to merge
1
commit into
lesson-1
Choose a base branch
from
lesson-6.1
base: lesson-1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
lesson 6 #8
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import sys | ||
|
|
||
|
|
||
| n = int(input('Введите целое трехзначное число ')) | ||
| #'n = 152' | ||
| # ОС Windows 10, 32 бит | ||
|
|
||
| a = n - n // 10 * 10 | ||
| b = n // 10 - n // 100 * 10 | ||
| c = n // 100 | ||
|
|
||
| result_mult = a * b * c | ||
| result_summ = a + b + c | ||
|
|
||
| def show_size(x): | ||
| summ_memory = sys.getsizeof(x) | ||
| if hasattr(x, '__iter__'): | ||
| if hasattr(x, 'items'): | ||
| for key, value in x.items(): | ||
| summ_memory += show_size(key) | ||
| summ_memory += show_size(value) | ||
| elif not isinstance(x, str): | ||
| for item in x: | ||
| summ_memory += show_size(item) | ||
| return summ_memory | ||
|
|
||
|
|
||
| def happy_end(x): | ||
| full_summ = 0 | ||
| for i in x: | ||
| full_summ += show_size(i) | ||
| return full_summ | ||
|
|
||
|
|
||
| def get_variables(): | ||
| loc_param = globals() | ||
| unwanted = ['get_variables', 'show_size', 'happy_end', 'sys'] | ||
| param = [] | ||
| for k in loc_param: | ||
| if '__' not in k: | ||
| if k not in unwanted: | ||
| param.append(loc_param[k]) | ||
| return param | ||
|
|
||
|
|
||
| print(f'Произведение чисел Вашего целого трехзначного числа равно={result_mult}') | ||
| print(f'Сумма чисел Вашего целого трехзначного числа равна: {result_summ}') | ||
|
|
||
| print(f'Всего задействовано памяти: {happy_end(get_variables())}') | ||
| #Всего задействовано памяти: 84 | ||
| #print(get_variables()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Посчитать четные и нечетные цифры введенного натурального числа. | ||
| # Например, если введено число 34560, то у него 3 четные цифры (4, 6 и 0) | ||
| # и 2 нечетные (3 и 5). | ||
|
|
||
|
|
||
| import time | ||
| import sys | ||
|
|
||
|
|
||
| def show_size(x): | ||
| summ_memory = sys.getsizeof(x) | ||
| if hasattr(x, '__iter__'): | ||
| if hasattr(x, 'items'): | ||
| for key, value in x.items(): | ||
| summ_memory += show_size(key) | ||
| summ_memory += show_size(value) | ||
| elif not isinstance(x, str): | ||
| for item in x: | ||
| summ_memory += show_size(item) | ||
| return summ_memory | ||
|
|
||
|
|
||
| def happy_end(x): | ||
| full_summ = 0 | ||
| for i in x: | ||
| full_summ += show_size(i) | ||
| return full_summ | ||
|
|
||
|
|
||
| def get_variables(): | ||
| loc_param = globals() | ||
| unwanted = ['get_variables', 'show_size', 'happy_end', 'sys', 'time'] | ||
|
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. Так же отлично. |
||
| param = [] | ||
| for k in loc_param: | ||
| if '__' not in k: | ||
| if k not in unwanted: | ||
| param.append(loc_param[k]) | ||
| return param | ||
|
|
||
|
|
||
| print('Расслабьтесь...') | ||
| time.sleep(1) | ||
| print('Сосредоточьтесь...') | ||
| time.sleep(1) | ||
| z = a = int(input('Запишите самое важное для Вас натуральное число...: '))# 3578 | ||
| # т.к. значение обнуляется = > объем памяти меняются во время выполнения скрипта для наглядности беру две переменные | ||
| # иначе ответ получается как и в предыдущей задаче, скука же. А обнуляющуюся переменную можно, при желании, исключить. | ||
|
|
||
| devil_even = 0 | ||
| devil_uneven = 0 | ||
|
|
||
|
|
||
| if a == 0: | ||
| print('Ваш очень важный ноль сугубо четный') | ||
| else: | ||
| while a != 0: | ||
| c = a % 10 % 2 | ||
| a = a // 10 | ||
| if c == 0: | ||
| devil_even += 1 | ||
| else: | ||
| devil_uneven += 1 | ||
| print('Ваше самое важное число содержит:') | ||
| print(devil_even, '- четных') | ||
| print(devil_uneven, '- нечетных') | ||
|
|
||
|
|
||
|
|
||
| print('До новых встреч!') | ||
| print(f'Итого было задействовано памяти: {happy_end(get_variables())}') | ||
| #Итого было задействовано памяти: 68 | ||
| #print(get_variables()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #В массиве случайных целых чисел поменять местами минимальный | ||
| # и максимальный элементы. | ||
|
|
||
| import random | ||
| import sys | ||
|
|
||
|
|
||
| def show_size(x): | ||
| summ_memory = sys.getsizeof(x) | ||
| if hasattr(x, '__iter__'): | ||
| if hasattr(x, 'items'): | ||
| for key, value in x.items(): | ||
| summ_memory += show_size(key) | ||
| summ_memory += show_size(value) | ||
| elif not isinstance(x, str): | ||
| for item in x: | ||
| summ_memory += show_size(item) | ||
| return summ_memory | ||
|
|
||
|
|
||
| def happy_end(x): | ||
| full_summ = 0 | ||
| for i in x: | ||
| full_summ += show_size(i) | ||
| return full_summ | ||
|
|
||
|
|
||
| def get_variables(): | ||
| loc_param = globals() | ||
| unwanted = ['get_variables', 'show_size', 'happy_end', 'sys', 'random'] | ||
| param = [] | ||
| for k in loc_param: | ||
| if '__' not in k: | ||
| if k not in unwanted: | ||
| param.append(loc_param[k]) | ||
| return param | ||
|
|
||
|
|
||
| SIZE = 10 | ||
| array = [random.randint(0, SIZE * SIZE) for _ in range(SIZE)] | ||
| #Старый массив: [2, 44, 79, 44, 75, 16, 97, 69, 59, 42] | ||
|
|
||
| minimum = maximum = array[0] | ||
|
|
||
| for i in range(1, len(array)): | ||
| if array[i] > maximum: | ||
| maximum = array[i] | ||
| elif array[i] < minimum: | ||
| minimum = array[i] | ||
| else: | ||
| pass | ||
| new_array = [] | ||
| for i in range(len(array)): | ||
| if array[i] == maximum: | ||
| new_array += [minimum] | ||
| elif array[i] == minimum: | ||
| new_array += [maximum] | ||
| else: | ||
| new_array += [array[i]] | ||
|
|
||
| print('Старый массив: ', array) | ||
| print('максимальный элемент:', maximum, 'минимальный элемент: ', minimum) | ||
| print('Новый массив:', new_array) | ||
| #Новый массив: [97, 44, 79, 44, 75, 16, 2, 69, 59, 42] | ||
| print(f'Итого было задействовано памяти: {happy_end(get_variables())}') | ||
| #Итого было задействовано памяти: 536 | ||
|
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(get_variables()) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Отличное решение.