-
Notifications
You must be signed in to change notification settings - Fork 0
Выполнение второго задания #2
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
silverAndr
wants to merge
1
commit into
main
Choose a base branch
from
lesson2
base: main
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
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,3 @@ | ||
| list = [1, 2.0, True, 'Hello', None, ['1', 2, 3.0], (1, 2, 3), {'name': 'Tom', 'second_name': 'Hardy'}, complex(2, 3), set(['a', 'b', 'c', 'b', 'a'])] | ||
| for item in list: | ||
| print(type(item)) |
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,18 @@ | ||
| # Для списка реализовать обмен значений соседних элементов | ||
| list_length = input('Введите длинну списка - ') | ||
| if not list_length.isdigit() or int(list_length) <= 0: # проверяем ввод длины списка | ||
| print('Длинна - это положительное, целое число') | ||
| exit() | ||
| list_length = int(list_length) | ||
| ind = 0 | ||
| list = [] | ||
| while ind < list_length: | ||
| list.insert(ind, input('Введите элемент ' + str(ind) + ' - ')) | ||
| ind += 1 | ||
| print(list) # выводим введенный список | ||
| index = 0 | ||
| for item in list: | ||
| if index % 2 == 1: | ||
| list[index], list[index-1] = list[index-1], list[index] | ||
| index += 1 | ||
| print(list) # выводим измененный список |
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,68 @@ | ||
| # Пользователь вводит месяц в виде целого числа от 1 до 12. | ||
| # Сообщить к какому времени года относится месяц (зима, весна, лето, осень). Напишите решения через list и через dict. | ||
| month = input('Введите месяц - ') | ||
| if not month.isdigit() or int(month) <= 0 or int(month) < 1 or int(month) > 12: # проверяем ввод месяца | ||
| print('Месяц - это положительное целое число, от 1 до 12') | ||
| exit() | ||
| month = int(month) | ||
| monthes = ['Зима', 'Зима', 'Весна', 'Весна', 'Весна', 'Лето', 'Лето', 'Лето', 'Осень', 'Осень', 'Осень', 'Зима'] | ||
| print(monthes[month-1]) # через список | ||
|
|
||
| dict_seasons = { | ||
| 1: 'Весна', | ||
| 2: 'Лето', | ||
| 3: 'Осень', | ||
| 4: 'Зима' | ||
| } | ||
| dict_monthes = { | ||
| 1: { | ||
| 'name': 'Январь', | ||
| 'season': 4 | ||
| }, | ||
| 2: { | ||
| 'name': 'Февраль', | ||
| 'season': 4 | ||
| }, | ||
| 3: { | ||
| 'name': 'Март', | ||
| 'season': 1 | ||
| }, | ||
| 4: { | ||
| 'name': 'Апрель', | ||
| 'season': 1 | ||
| }, | ||
| 5: { | ||
| 'name': 'Май', | ||
| 'season': 1 | ||
| }, | ||
| 6: { | ||
| 'name': 'Июнь', | ||
| 'season': 2 | ||
| }, | ||
| 7: { | ||
| 'name': 'Июль', | ||
| 'season': 2 | ||
| }, | ||
| 8: { | ||
| 'name': 'Август', | ||
| 'season': 2 | ||
| }, | ||
| 9: { | ||
| 'name': 'Сентябрь', | ||
| 'season': 3 | ||
| }, | ||
| 10: { | ||
| 'name': 'Октябрь', | ||
| 'season': 3 | ||
| }, | ||
| 11: { | ||
| 'name': 'Ноябрь', | ||
| 'season': 3 | ||
| }, | ||
| 12: { | ||
| 'name': 'Декабрь', | ||
| 'season': 4 | ||
| } | ||
| } | ||
| dict_month = dict_monthes.get(month) | ||
| print('Месяц ' + dict_month['name'] + '. Время года - ' + dict_seasons[dict_month['season']] + '!') # через словарь |
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,6 @@ | ||
| # Пользователь вводит строку из нескольких слов, разделённых пробелами. Вывести каждое слово с новой строки. | ||
| # Строки необходимо пронумеровать. Если в слово длинное, выводить только первые 10 букв в слове | ||
| long_string = input('Введите сроку: ') | ||
| list_words = long_string.split() | ||
| for ind, word in enumerate(list_words, 1): | ||
| print(ind, word[:9]) | ||
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,11 @@ | ||
| # Реализовать структуру «Рейтинг», представляющую собой не возрастающий набор натуральных чисел. | ||
| rating = [9, 5, 2, 1] | ||
| while True: # Запрашиваем новые элементы, пока программа не будет остановлена | ||
| new_element = input('Введите новый элемент рейтинга - ') | ||
| if not new_element.isdigit() or int(new_element) < 1: # проверяем, что число натуральное | ||
| print('Введенное значение должно быть натуральным числом!') | ||
| continue | ||
| new_element = int(new_element) | ||
| rating.append(new_element) # добавляем новый элемент в конец рейтинга | ||
| rating.sort() # Сортируем рейтинг | ||
| print(rating) |
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,28 @@ | ||
| # Реализовать структуру данных «Товары». | ||
| products = [] | ||
| product_params = {'name': 'Название', 'price': 'цена', 'count': 'Количество', 'ed': 'ед'} | ||
|
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. Хорошая идея сделать отдельно названия для вывода |
||
| ind = 0 | ||
| while True: | ||
| print('Введите товар', str(ind+1)) | ||
| current_params = {} | ||
| for param in product_params.keys(): | ||
| new_value = input(product_params[param] + ': ') | ||
| if new_value.isdigit() : | ||
| new_value = int(new_value) | ||
| current_params[param] = new_value | ||
| products.append((ind, current_params)) | ||
| if input('"0" для завершения ввода: ') == '0': | ||
| break | ||
| ind += 1 | ||
| print('Вы ввели: ') | ||
| print(products) | ||
| result = {} | ||
| for param in product_params: | ||
| result[param] = set([]) | ||
| for product in products: | ||
| for param in product_params: | ||
| result[param].add(product[1][param]) | ||
| for param in product_params: | ||
| result[param] = list(result[param]) | ||
| print('Аналитика:') | ||
| print(result) | ||
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.
Почему 9) последний не включается же
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.
Поспешил, запустил код с :10, и показалось не правильно вывелось. Вообщем недо-тест.